1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
normal 2017-10-31 19:10:19 +00:00
parent 5f77f1e30d
commit c9d41f6055
2 changed files with 12 additions and 12 deletions

4
dir.c
View file

@ -1218,10 +1218,10 @@ static VALUE
dir_s_mkdir(int argc, VALUE *argv, VALUE obj)
{
VALUE path, vmode;
int mode;
mode_t mode;
if (rb_scan_args(argc, argv, "11", &path, &vmode) == 2) {
mode = NUM2INT(vmode);
mode = NUM2MODET(vmode);
}
else {
mode = 0777;

20
file.c
View file

@ -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__