ruby-changes:65851
From: Nobuyoshi <ko1@a...>
Date: Mon, 12 Apr 2021 15:58:29 +0900 (JST)
Subject: [ruby-changes:65851] a5688b5ce6 (master): Support non-standard `struct stat` [Bug #17793]
https://git.ruby-lang.org/ruby.git/commit/?id=a5688b5ce6 From a5688b5ce6e87a5b881a4d52d4e59b6fe807e807 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 12 Apr 2021 14:42:26 +0900 Subject: 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` --- configure.ac | 5 +++++ file.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/configure.ac b/configure.ac index 6fe43bf..27899f7 100644 --- a/configure.ac +++ b/configure.ac @@ -1693,6 +1693,7 @@ RUBY_CHECK_SIGNEDNESS(size_t, [AC_MSG_ERROR(size_t is signed)], [], https://github.com/ruby/ruby/blob/trunk/configure.ac#L1693 [@%:@include <sys/types.h>]) RUBY_CHECK_SIZEOF(size_t, [int long void*], [], [@%:@include <sys/types.h>]) RUBY_CHECK_SIZEOF(ptrdiff_t, size_t, [], [@%:@include <stddef.h>]) +RUBY_CHECK_SIZEOF(dev_t) RUBY_CHECK_PRINTF_PREFIX(size_t, z) RUBY_CHECK_PRINTF_PREFIX(ptrdiff_t, t) AC_CHECK_MEMBERS([struct stat.st_blksize]) @@ -1703,6 +1704,10 @@ AS_IF([test "$ac_cv_member_struct_stat_st_blocks" = yes], [ https://github.com/ruby/ruby/blob/trunk/configure.ac#L1704 RUBY_CHECK_SIZEOF([struct stat.st_blocks], [off_t int long "long long"], [], [@%:@include <sys/stat.h>]) ]) RUBY_CHECK_SIZEOF([struct stat.st_ino], [long "long long"], [], [@%:@include <sys/stat.h>]) +RUBY_CHECK_SIZEOF([struct stat.st_dev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>]) +AS_IF([test "$ac_cv_member_struct_stat_st_rdev" = yes], [ + RUBY_CHECK_SIZEOF([struct stat.st_rdev], [dev_t int long "long long"], [], [@%:@include <sys/stat.h>]) +]) AC_CHECK_MEMBERS([struct stat.st_atim]) AC_CHECK_MEMBERS([struct stat.st_atimespec]) AC_CHECK_MEMBERS([struct stat.st_atimensec]) diff --git a/file.c b/file.c index 6e6dfbc..3a758c1 100644 --- a/file.c +++ b/file.c @@ -577,7 +577,13 @@ rb_stat_cmp(VALUE self, VALUE other) https://github.com/ruby/ruby/blob/trunk/file.c#L577 static VALUE rb_stat_dev(VALUE self) { +#if SIZEOF_STRUCT_STAT_ST_DEV <= SIZEOF_DEV_T return DEVT2NUM(get_stat(self)->st_dev); +#elif SIZEOF_STRUCT_STAT_ST_DEV <= SIZEOF_LONG + return ULONG2NUM(get_stat(self)->st_dev); +#else + return ULL2NUM(get_stat(self)->st_dev); +#endif } /* @@ -747,7 +753,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L753 rb_stat_rdev(VALUE self) { #ifdef HAVE_STRUCT_STAT_ST_RDEV +# if SIZEOF_STRUCT_STAT_ST_RDEV <= SIZEOF_DEV_T return DEVT2NUM(get_stat(self)->st_rdev); +# elif SIZEOF_STRUCT_STAT_ST_RDEV <= SIZEOF_LONG + return ULONG2NUM(get_stat(self)->st_rdev); +# else + return ULL2NUM(get_stat(self)->st_rdev); +# endif #else return Qnil; #endif @@ -6254,7 +6266,11 @@ path_check_0(VALUE path) https://github.com/ruby/ruby/blob/trunk/file.c#L6266 #endif && !access(p0, W_OK)) { rb_enc_warn(enc, "Insecure world writable dir %s in PATH, mode 0%" +#if SIZEOF_DEV_T > SIZEOF_INT PRI_MODET_PREFIX"o", +#else + "o", +#endif p0, st.st_mode); if (p) *p = '/'; RB_GC_GUARD(path); -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/