diff options
author | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-31 19:10:19 +0000 |
---|---|---|
committer | normal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-31 19:10:19 +0000 |
commit | c9d41f60550bc9451b08009940376908f4144054 (patch) | |
tree | 358bfee02416d61619a629cf9e2fe3daa4874ac9 /file.c | |
parent | 5f77f1e30dcce93e6067aa484a6d87c5df1eb958 (diff) |
use mode_t where applicable (instead of int)
mode_t is the correct type for these syscalls and it can be
easier-to-understand. It may also help portability to future
platforms and improve type checking.
* dir.c (dir_s_mkdir): use mode_t for mkdir(2)
* file.c (chmod_internal): use mode_t for chmod(2)
(rb_file_s_chmod): s/int/mode_t/
(lchmod_internal): ditto, deref pointer as in chmod_internal
(rb_file_s_lchmod): pass pointer as in rb_file_s_chmod
(rb_file_s_rename): use mode_t for umask(2)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'file.c')
-rw-r--r-- | file.c | 20 |
1 files changed, 10 insertions, 10 deletions
@@ -2388,7 +2388,7 @@ rb_file_size(VALUE obj) static int chmod_internal(const char *path, void *mode) { - return chmod(path, *(int *)mode); + return chmod(path, *(mode_t *)mode); } /* @@ -2407,10 +2407,10 @@ chmod_internal(const char *path, void *mode) static VALUE rb_file_s_chmod(int argc, VALUE *argv) { - int mode; + mode_t mode; apply2args(1); - mode = NUM2INT(*argv++); + mode = NUM2MODET(*argv++); return apply2files(chmod_internal, argc, argv, &mode); } @@ -2463,7 +2463,7 @@ rb_file_chmod(VALUE obj, VALUE vmode) static int lchmod_internal(const char *path, void *mode) { - return lchmod(path, (int)(VALUE)mode); + return lchmod(path, *(mode_t *)mode); } /* @@ -2479,12 +2479,12 @@ lchmod_internal(const char *path, void *mode) static VALUE rb_file_s_lchmod(int argc, VALUE *argv) { - long mode; + mode_t mode; apply2args(1); - mode = NUM2INT(*argv++); + mode = NUM2MODET(*argv++); - return apply2files(lchmod_internal, argc, argv, (void *)(long)mode); + return apply2files(lchmod_internal, argc, argv, &mode); } #else #define rb_file_s_lchmod rb_f_notimplement @@ -3007,19 +3007,19 @@ rb_file_s_rename(VALUE klass, VALUE from, VALUE to) static VALUE rb_file_s_umask(int argc, VALUE *argv) { - int omask = 0; + mode_t omask = 0; if (argc == 0) { omask = umask(0); umask(omask); } else if (argc == 1) { - omask = umask(NUM2INT(argv[0])); + omask = umask(NUM2MODET(argv[0])); } else { rb_check_arity(argc, 0, 1); } - return INT2FIX(omask); + return MODET2NUM(omask); } #ifdef __CYGWIN__ |