* io.c: use mode_t for the 3rd argument, permission, of open(2).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18735 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-08-20 16:10:36 +00:00
Родитель 99155ccbf2
Коммит 10e5d07681
2 изменённых файлов: 34 добавлений и 30 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Thu Aug 21 01:09:26 2008 Tanaka Akira <akr@fsij.org>
* io.c: use mode_t for the 3rd argument, permission, of open(2).
Thu Aug 21 00:51:42 2008 Shugo Maeda <shugo@netlab.jp> Thu Aug 21 00:51:42 2008 Shugo Maeda <shugo@netlab.jp>
* configure.in: removed strftime from AC_REPLACE_FUNCS(). * configure.in: removed strftime from AC_REPLACE_FUNCS().

60
io.c
Просмотреть файл

@ -3852,7 +3852,7 @@ rb_io_extract_modeenc(VALUE mode, VALUE opthash,
struct sysopen_struct { struct sysopen_struct {
char *fname; char *fname;
int flag; int flag;
unsigned int mode; mode_t mode;
}; };
static VALUE static VALUE
@ -3863,7 +3863,7 @@ sysopen_func(void *ptr)
} }
static int static int
rb_sysopen_internal(char *fname, int flags, unsigned int mode) rb_sysopen_internal(char *fname, int flags, mode_t mode)
{ {
struct sysopen_struct data; struct sysopen_struct data;
data.fname = fname; data.fname = fname;
@ -3873,7 +3873,7 @@ rb_sysopen_internal(char *fname, int flags, unsigned int mode)
} }
static int static int
rb_sysopen(char *fname, int flags, unsigned int mode) rb_sysopen(char *fname, int flags, mode_t mode)
{ {
int fd; int fd;
@ -3938,7 +3938,7 @@ io_check_tty(rb_io_t *fptr)
} }
static VALUE static VALUE
rb_file_open_generic(VALUE io, const char *fname, int modenum, int flags, convconfig_t *convconfig, int perm) rb_file_open_generic(VALUE io, const char *fname, int modenum, int flags, convconfig_t *convconfig, mode_t perm)
{ {
rb_io_t *fptr; rb_io_t *fptr;
@ -3989,13 +3989,13 @@ rb_file_open(const char *fname, const char *mode)
} }
static VALUE static VALUE
rb_file_sysopen_internal(VALUE io, const char *fname, int modenum, int perm) rb_file_sysopen_internal(VALUE io, const char *fname, int modenum, mode_t perm)
{ {
return rb_file_open_generic(io, fname, modenum, rb_io_modenum_flags(modenum), NULL, perm); return rb_file_open_generic(io, fname, modenum, rb_io_modenum_flags(modenum), NULL, perm);
} }
VALUE VALUE
rb_file_sysopen(const char *fname, int modenum, int perm) rb_file_sysopen(const char *fname, int modenum, mode_t perm)
{ {
return rb_file_sysopen_internal(io_alloc(rb_cFile), fname, modenum, perm); return rb_file_sysopen_internal(io_alloc(rb_cFile), fname, modenum, perm);
} }
@ -4512,11 +4512,11 @@ rb_io_s_popen(int argc, VALUE *argv, VALUE klass)
static void static void
rb_scan_open_args(int argc, VALUE *argv, rb_scan_open_args(int argc, VALUE *argv,
VALUE *fname_p, int *modenum_p, int *flags_p, VALUE *fname_p, int *modenum_p, int *flags_p,
convconfig_t *convconfig_p, unsigned int *fmode_p) convconfig_t *convconfig_p, mode_t *perm_p)
{ {
VALUE opt=Qnil, fname, vmode, perm; VALUE opt=Qnil, fname, vmode, vperm;
int modenum, flags; int modenum, flags;
unsigned int fmode; mode_t perm;
if (0 < argc) { if (0 < argc) {
opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash"); opt = rb_check_convert_type(argv[argc-1], T_HASH, "Hash", "to_hash");
@ -4525,7 +4525,7 @@ rb_scan_open_args(int argc, VALUE *argv,
} }
} }
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
#if defined _WIN32 || defined __APPLE__ #if defined _WIN32 || defined __APPLE__
{ {
static rb_encoding *fs_encoding; static rb_encoding *fs_encoding;
@ -4549,12 +4549,12 @@ rb_scan_open_args(int argc, VALUE *argv,
rb_io_extract_modeenc(vmode, opt, &modenum, &flags, convconfig_p); rb_io_extract_modeenc(vmode, opt, &modenum, &flags, convconfig_p);
fmode = NIL_P(perm) ? 0666 : NUM2UINT(perm); perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
*fname_p = fname; *fname_p = fname;
*modenum_p = modenum; *modenum_p = modenum;
*flags_p = flags; *flags_p = flags;
*fmode_p = fmode; *perm_p = perm;
} }
static VALUE static VALUE
@ -4563,10 +4563,10 @@ rb_open_file(int argc, VALUE *argv, VALUE io)
VALUE fname; VALUE fname;
int modenum, flags; int modenum, flags;
convconfig_t convconfig; convconfig_t convconfig;
unsigned int fmode; mode_t perm;
rb_scan_open_args(argc, argv, &fname, &modenum, &flags, &convconfig, &fmode); rb_scan_open_args(argc, argv, &fname, &modenum, &flags, &convconfig, &perm);
rb_file_open_generic(io, RSTRING_PTR(fname), modenum, flags, &convconfig, fmode); rb_file_open_generic(io, RSTRING_PTR(fname), modenum, flags, &convconfig, perm);
return io; return io;
} }
@ -4610,12 +4610,12 @@ rb_io_s_open(int argc, VALUE *argv, VALUE klass)
static VALUE static VALUE
rb_io_s_sysopen(int argc, VALUE *argv) rb_io_s_sysopen(int argc, VALUE *argv)
{ {
VALUE fname, vmode, perm; VALUE fname, vmode, vperm;
int flags, fd; int flags, fd;
unsigned int fmode; mode_t perm;
char *path; char *path;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); rb_scan_args(argc, argv, "12", &fname, &vmode, &vperm);
FilePathValue(fname); FilePathValue(fname);
if (NIL_P(vmode)) flags = O_RDONLY; if (NIL_P(vmode)) flags = O_RDONLY;
@ -4624,12 +4624,12 @@ rb_io_s_sysopen(int argc, VALUE *argv)
SafeStringValue(vmode); SafeStringValue(vmode);
flags = rb_io_mode_modenum(StringValueCStr(vmode)); flags = rb_io_mode_modenum(StringValueCStr(vmode));
} }
if (NIL_P(perm)) fmode = 0666; if (NIL_P(vperm)) perm = 0666;
else fmode = NUM2UINT(perm); else perm = NUM2UINT(vperm);
RB_GC_GUARD(fname) = rb_str_new4(fname); RB_GC_GUARD(fname) = rb_str_new4(fname);
path = RSTRING_PTR(fname); path = RSTRING_PTR(fname);
fd = rb_sysopen(path, flags, fmode); fd = rb_sysopen(path, flags, perm);
return INT2NUM(fd); return INT2NUM(fd);
} }
@ -5465,17 +5465,17 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
{ {
VALUE fnum, mode, orig; VALUE fnum, mode, orig;
rb_io_t *fp, *ofp = NULL; rb_io_t *fp, *ofp = NULL;
int fd, fmode, flags = O_RDONLY; int fd, flags, modenum = O_RDONLY;
rb_secure(4); rb_secure(4);
rb_scan_args(argc, argv, "11", &fnum, &mode); rb_scan_args(argc, argv, "11", &fnum, &mode);
if (argc == 2) { if (argc == 2) {
if (FIXNUM_P(mode)) { if (FIXNUM_P(mode)) {
flags = FIX2LONG(mode); modenum = FIX2LONG(mode);
} }
else { else {
SafeStringValue(mode); SafeStringValue(mode);
flags = rb_io_mode_modenum(StringValueCStr(mode)); modenum = rb_io_mode_modenum(StringValueCStr(mode));
} }
} }
orig = rb_io_check_io(fnum); orig = rb_io_check_io(fnum);
@ -5484,13 +5484,13 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
UPDATE_MAXFD(fd); UPDATE_MAXFD(fd);
if (argc != 2) { if (argc != 2) {
#if defined(HAVE_FCNTL) && defined(F_GETFL) #if defined(HAVE_FCNTL) && defined(F_GETFL)
flags = fcntl(fd, F_GETFL); modenum = fcntl(fd, F_GETFL);
if (flags == -1) rb_sys_fail(0); if (modenum == -1) rb_sys_fail(0);
#endif #endif
} }
MakeOpenFile(io, fp); MakeOpenFile(io, fp);
fp->fd = fd; fp->fd = fd;
fp->mode = rb_io_modenum_flags(flags); fp->mode = rb_io_modenum_flags(modenum);
io_check_tty(fp); io_check_tty(fp);
} }
else if (RFILE(io)->fptr) { else if (RFILE(io)->fptr) {
@ -5503,10 +5503,10 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s)); rb_raise(rb_eIOError, "too many shared IO for %s", StringValueCStr(s));
} }
if (argc == 2) { if (argc == 2) {
fmode = rb_io_modenum_flags(flags); flags = rb_io_modenum_flags(modenum);
if ((ofp->mode ^ fmode) & (FMODE_READWRITE|FMODE_BINMODE)) { if ((ofp->mode ^ flags) & (FMODE_READWRITE|FMODE_BINMODE)) {
if (FIXNUM_P(mode)) { if (FIXNUM_P(mode)) {
rb_raise(rb_eArgError, "incompatible mode 0x%x", flags); rb_raise(rb_eArgError, "incompatible mode 0x%x", modenum);
} }
else { else {
rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode)); rb_raise(rb_eArgError, "incompatible mode \"%s\"", RSTRING_PTR(mode));