Skip to content

Commit a5688b5

Browse files
committed
Support non-standard struct stat [Bug #17793]
On 32-bit Android: * `st_dev`/`st_rdev` are not `dev_t` * `st_mode` is not `mode_t`
1 parent 799ea1d commit a5688b5

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

configure.ac

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,7 @@ RUBY_CHECK_SIGNEDNESS(size_t, [AC_MSG_ERROR(size_t is signed)], [],
16931693
[@%:@include <sys/types.h>])
16941694
RUBY_CHECK_SIZEOF(size_t, [int long void*], [], [@%:@include <sys/types.h>])
16951695
RUBY_CHECK_SIZEOF(ptrdiff_t, size_t, [], [@%:@include <stddef.h>])
1696+
RUBY_CHECK_SIZEOF(dev_t)
16961697
RUBY_CHECK_PRINTF_PREFIX(size_t, z)
16971698
RUBY_CHECK_PRINTF_PREFIX(ptrdiff_t, t)
16981699
AC_CHECK_MEMBERS([struct stat.st_blksize])
@@ -1703,6 +1704,10 @@ AS_IF([test "$ac_cv_member_struct_stat_st_blocks" = yes], [
17031704
RUBY_CHECK_SIZEOF([struct stat.st_blocks], [off_t int long "long long"], [], [@%:@include <sys/stat.h>])
17041705
])
17051706
RUBY_CHECK_SIZEOF([struct stat.st_ino], [long "long long"], [], [@%:@include <sys/stat.h>])
1707+
RUBY_CHECK_SIZEOF([struct stat.st_dev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>])
1708+
AS_IF([test "$ac_cv_member_struct_stat_st_rdev" = yes], [
1709+
RUBY_CHECK_SIZEOF([struct stat.st_rdev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>])
1710+
])
17061711
AC_CHECK_MEMBERS([struct stat.st_atim])
17071712
AC_CHECK_MEMBERS([struct stat.st_atimespec])
17081713
AC_CHECK_MEMBERS([struct stat.st_atimensec])

file.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,13 @@ rb_stat_cmp(VALUE self, VALUE other)
577577
static VALUE
578578
rb_stat_dev(VALUE self)
579579
{
580+
#if SIZEOF_STRUCT_STAT_ST_DEV <= SIZEOF_DEV_T
580581
return DEVT2NUM(get_stat(self)->st_dev);
582+
#elif SIZEOF_STRUCT_STAT_ST_DEV <= SIZEOF_LONG
583+
return ULONG2NUM(get_stat(self)->st_dev);
584+
#else
585+
return ULL2NUM(get_stat(self)->st_dev);
586+
#endif
581587
}
582588

583589
/*
@@ -747,7 +753,13 @@ static VALUE
747753
rb_stat_rdev(VALUE self)
748754
{
749755
#ifdef HAVE_STRUCT_STAT_ST_RDEV
756+
# if SIZEOF_STRUCT_STAT_ST_RDEV <= SIZEOF_DEV_T
750757
return DEVT2NUM(get_stat(self)->st_rdev);
758+
# elif SIZEOF_STRUCT_STAT_ST_RDEV <= SIZEOF_LONG
759+
return ULONG2NUM(get_stat(self)->st_rdev);
760+
# else
761+
return ULL2NUM(get_stat(self)->st_rdev);
762+
# endif
751763
#else
752764
return Qnil;
753765
#endif
@@ -6254,7 +6266,11 @@ path_check_0(VALUE path)
62546266
#endif
62556267
&& !access(p0, W_OK)) {
62566268
rb_enc_warn(enc, "Insecure world writable dir %s in PATH, mode 0%"
6269+
#if SIZEOF_DEV_T > SIZEOF_INT
62576270
PRI_MODET_PREFIX"o",
6271+
#else
6272+
"o",
6273+
#endif
62586274
p0, st.st_mode);
62596275
if (p) *p = '/';
62606276
RB_GC_GUARD(path);

0 commit comments

Comments
 (0)