* io.c: variables renamed for consistency.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@19126 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c56ef25cf9
commit
b53f7a1cbf
@ -1,3 +1,7 @@
|
|||||||
|
Thu Sep 4 20:19:36 2008 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* io.c: variables renamed for consistency.
|
||||||
|
|
||||||
Thu Sep 4 19:40:50 2008 Narihiro Nakamura <authorNari@gmail.com>
|
Thu Sep 4 19:40:50 2008 Narihiro Nakamura <authorNari@gmail.com>
|
||||||
|
|
||||||
* gc.c (gc_profile_record_get): to static function.
|
* gc.c (gc_profile_record_get): to static function.
|
||||||
|
136
io.c
136
io.c
@ -1194,19 +1194,19 @@ rb_io_sync(VALUE io)
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_set_sync(VALUE io, VALUE mode)
|
rb_io_set_sync(VALUE io, VALUE sync)
|
||||||
{
|
{
|
||||||
rb_io_t *fptr;
|
rb_io_t *fptr;
|
||||||
|
|
||||||
io = GetWriteIO(io);
|
io = GetWriteIO(io);
|
||||||
GetOpenFile(io, fptr);
|
GetOpenFile(io, fptr);
|
||||||
if (RTEST(mode)) {
|
if (RTEST(sync)) {
|
||||||
fptr->mode |= FMODE_SYNC;
|
fptr->mode |= FMODE_SYNC;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fptr->mode &= ~FMODE_SYNC;
|
fptr->mode &= ~FMODE_SYNC;
|
||||||
}
|
}
|
||||||
return mode;
|
return sync;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1611,18 +1611,18 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
|
|||||||
void
|
void
|
||||||
rb_io_set_nonblock(rb_io_t *fptr)
|
rb_io_set_nonblock(rb_io_t *fptr)
|
||||||
{
|
{
|
||||||
int flags;
|
int modenum;
|
||||||
#ifdef F_GETFL
|
#ifdef F_GETFL
|
||||||
flags = fcntl(fptr->fd, F_GETFL);
|
modenum = fcntl(fptr->fd, F_GETFL);
|
||||||
if (flags == -1) {
|
if (modenum == -1) {
|
||||||
rb_sys_fail_path(fptr->pathv);
|
rb_sys_fail_path(fptr->pathv);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
flags = 0;
|
modenum = 0;
|
||||||
#endif
|
#endif
|
||||||
if ((flags & O_NONBLOCK) == 0) {
|
if ((modenum & O_NONBLOCK) == 0) {
|
||||||
flags |= O_NONBLOCK;
|
modenum |= O_NONBLOCK;
|
||||||
if (fcntl(fptr->fd, F_SETFL, flags) == -1) {
|
if (fcntl(fptr->fd, F_SETFL, modenum) == -1) {
|
||||||
rb_sys_fail_path(fptr->pathv);
|
rb_sys_fail_path(fptr->pathv);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3612,11 +3612,11 @@ rb_io_mode_flags(const char *mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_io_modenum_flags(int mode)
|
rb_io_modenum_flags(int modenum)
|
||||||
{
|
{
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
switch (modenum & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
||||||
case O_RDONLY:
|
case O_RDONLY:
|
||||||
flags = FMODE_READABLE;
|
flags = FMODE_READABLE;
|
||||||
break;
|
break;
|
||||||
@ -3628,17 +3628,17 @@ rb_io_modenum_flags(int mode)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mode & O_APPEND) {
|
if (modenum & O_APPEND) {
|
||||||
flags |= FMODE_APPEND;
|
flags |= FMODE_APPEND;
|
||||||
}
|
}
|
||||||
if (mode & O_TRUNC) {
|
if (modenum & O_TRUNC) {
|
||||||
flags |= FMODE_TRUNC;
|
flags |= FMODE_TRUNC;
|
||||||
}
|
}
|
||||||
if (mode & O_CREAT) {
|
if (modenum & O_CREAT) {
|
||||||
flags |= FMODE_CREATE;
|
flags |= FMODE_CREATE;
|
||||||
}
|
}
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
if (mode & O_BINARY) {
|
if (modenum & O_BINARY) {
|
||||||
flags |= FMODE_BINMODE;
|
flags |= FMODE_BINMODE;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -3649,36 +3649,36 @@ rb_io_modenum_flags(int mode)
|
|||||||
static int
|
static int
|
||||||
rb_io_flags_modenum(int flags)
|
rb_io_flags_modenum(int flags)
|
||||||
{
|
{
|
||||||
int mode = 0;
|
int modenum = 0;
|
||||||
|
|
||||||
switch (flags & FMODE_READWRITE) {
|
switch (flags & FMODE_READWRITE) {
|
||||||
case FMODE_READABLE:
|
case FMODE_READABLE:
|
||||||
mode |= O_RDONLY;
|
modenum |= O_RDONLY;
|
||||||
break;
|
break;
|
||||||
case FMODE_WRITABLE:
|
case FMODE_WRITABLE:
|
||||||
mode |= O_WRONLY;
|
modenum |= O_WRONLY;
|
||||||
break;
|
break;
|
||||||
case FMODE_READWRITE:
|
case FMODE_READWRITE:
|
||||||
mode |= O_RDWR;
|
modenum |= O_RDWR;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & FMODE_APPEND) {
|
if (flags & FMODE_APPEND) {
|
||||||
mode |= O_APPEND;
|
modenum |= O_APPEND;
|
||||||
}
|
}
|
||||||
if (flags & FMODE_TRUNC) {
|
if (flags & FMODE_TRUNC) {
|
||||||
mode |= O_TRUNC;
|
modenum |= O_TRUNC;
|
||||||
}
|
}
|
||||||
if (flags & FMODE_CREATE) {
|
if (flags & FMODE_CREATE) {
|
||||||
mode |= O_CREAT;
|
modenum |= O_CREAT;
|
||||||
}
|
}
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
if (flags & FMODE_BINMODE) {
|
if (flags & FMODE_BINMODE) {
|
||||||
mode |= O_BINARY;
|
modenum |= O_BINARY;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return mode;
|
return modenum;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -3690,20 +3690,20 @@ rb_io_mode_modenum(const char *mode)
|
|||||||
#define MODENUM_MAX 4
|
#define MODENUM_MAX 4
|
||||||
|
|
||||||
static const char*
|
static const char*
|
||||||
rb_io_modenum_mode(int flags)
|
rb_io_modenum_mode(int modenum)
|
||||||
{
|
{
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
# define MODE_BINARY(a,b) ((flags & O_BINARY) ? (b) : (a))
|
# define MODE_BINARY(a,b) ((modenum & O_BINARY) ? (b) : (a))
|
||||||
#else
|
#else
|
||||||
# define MODE_BINARY(a,b) (a)
|
# define MODE_BINARY(a,b) (a)
|
||||||
#endif
|
#endif
|
||||||
if (flags & O_APPEND) {
|
if (modenum & O_APPEND) {
|
||||||
if ((flags & O_RDWR) == O_RDWR) {
|
if ((modenum & O_RDWR) == O_RDWR) {
|
||||||
return MODE_BINARY("a+", "ab+");
|
return MODE_BINARY("a+", "ab+");
|
||||||
}
|
}
|
||||||
return MODE_BINARY("a", "ab");
|
return MODE_BINARY("a", "ab");
|
||||||
}
|
}
|
||||||
switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
switch (modenum & (O_RDONLY|O_WRONLY|O_RDWR)) {
|
||||||
case O_RDONLY:
|
case O_RDONLY:
|
||||||
return MODE_BINARY("r", "rb");
|
return MODE_BINARY("r", "rb");
|
||||||
case O_WRONLY:
|
case O_WRONLY:
|
||||||
@ -3711,7 +3711,7 @@ rb_io_modenum_mode(int flags)
|
|||||||
case O_RDWR:
|
case O_RDWR:
|
||||||
return MODE_BINARY("r+", "rb+");
|
return MODE_BINARY("r+", "rb+");
|
||||||
}
|
}
|
||||||
rb_raise(rb_eArgError, "invalid access modenum 0x%x", flags);
|
rb_raise(rb_eArgError, "invalid access modenum 0x%x", modenum);
|
||||||
return NULL; /* not reached */
|
return NULL; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3834,10 +3834,10 @@ io_extract_encoding_option(VALUE opt, rb_encoding **enc_p, rb_encoding **enc2_p)
|
|||||||
typedef struct rb_io_enc_t convconfig_t;
|
typedef struct rb_io_enc_t convconfig_t;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash,
|
rb_io_extract_modeenc(VALUE *vmode_p, VALUE opthash,
|
||||||
int *modenum_p, int *flags_p, convconfig_t *convconfig_p)
|
int *modenum_p, int *flags_p, convconfig_t *convconfig_p)
|
||||||
{
|
{
|
||||||
VALUE mode;
|
VALUE vmode;
|
||||||
int modenum, flags;
|
int modenum, flags;
|
||||||
rb_encoding *enc, *enc2;
|
rb_encoding *enc, *enc2;
|
||||||
int ecflags;
|
int ecflags;
|
||||||
@ -3845,24 +3845,24 @@ rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash,
|
|||||||
int has_enc = 0;
|
int has_enc = 0;
|
||||||
VALUE intmode;
|
VALUE intmode;
|
||||||
|
|
||||||
mode = *mode_p;
|
vmode = *vmode_p;
|
||||||
|
|
||||||
enc = NULL;
|
enc = NULL;
|
||||||
enc2 = NULL;
|
enc2 = NULL;
|
||||||
|
|
||||||
if (NIL_P(mode)) {
|
if (NIL_P(vmode)) {
|
||||||
flags = FMODE_READABLE;
|
flags = FMODE_READABLE;
|
||||||
modenum = O_RDONLY;
|
modenum = O_RDONLY;
|
||||||
}
|
}
|
||||||
else if (!NIL_P(intmode = rb_check_to_integer(mode, "to_int"))) {
|
else if (!NIL_P(intmode = rb_check_to_integer(vmode, "to_int"))) {
|
||||||
mode = intmode;
|
vmode = intmode;
|
||||||
modenum = NUM2INT(intmode);
|
modenum = NUM2INT(intmode);
|
||||||
flags = rb_io_modenum_flags(modenum);
|
flags = rb_io_modenum_flags(modenum);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const char *p;
|
const char *p;
|
||||||
SafeStringValue(mode);
|
SafeStringValue(vmode);
|
||||||
p = StringValueCStr(mode);
|
p = StringValueCStr(vmode);
|
||||||
flags = rb_io_mode_flags(p);
|
flags = rb_io_mode_flags(p);
|
||||||
modenum = rb_io_flags_modenum(flags);
|
modenum = rb_io_flags_modenum(flags);
|
||||||
p = strchr(p, ':');
|
p = strchr(p, ':');
|
||||||
@ -3900,7 +3900,7 @@ rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash,
|
|||||||
if ((flags & FMODE_BINMODE) && (flags & FMODE_TEXTMODE))
|
if ((flags & FMODE_BINMODE) && (flags & FMODE_TEXTMODE))
|
||||||
rb_raise(rb_eArgError, "both textmode and binmode specified");
|
rb_raise(rb_eArgError, "both textmode and binmode specified");
|
||||||
|
|
||||||
*mode_p = mode;
|
*vmode_p = vmode;
|
||||||
|
|
||||||
*modenum_p = modenum;
|
*modenum_p = modenum;
|
||||||
*flags_p = flags;
|
*flags_p = flags;
|
||||||
@ -3912,41 +3912,41 @@ rb_io_extract_modeenc(VALUE *mode_p, VALUE opthash,
|
|||||||
|
|
||||||
struct sysopen_struct {
|
struct sysopen_struct {
|
||||||
const char *fname;
|
const char *fname;
|
||||||
int flag;
|
int modenum;
|
||||||
mode_t mode;
|
mode_t perm;
|
||||||
};
|
};
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
sysopen_func(void *ptr)
|
sysopen_func(void *ptr)
|
||||||
{
|
{
|
||||||
struct sysopen_struct *data = ptr;
|
struct sysopen_struct *data = ptr;
|
||||||
return (VALUE)open(data->fname, data->flag, data->mode);
|
return (VALUE)open(data->fname, data->modenum, data->perm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_sysopen_internal(const char *fname, int flags, mode_t mode)
|
rb_sysopen_internal(const char *fname, int modenum, mode_t perm)
|
||||||
{
|
{
|
||||||
struct sysopen_struct data;
|
struct sysopen_struct data;
|
||||||
data.fname = fname;
|
data.fname = fname;
|
||||||
data.flag = flags;
|
data.modenum = modenum;
|
||||||
data.mode = mode;
|
data.perm = perm;
|
||||||
return (int)rb_thread_blocking_region(sysopen_func, &data, RUBY_UBF_IO, 0);
|
return (int)rb_thread_blocking_region(sysopen_func, &data, RUBY_UBF_IO, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
rb_sysopen(const char *fname, int flags, mode_t mode)
|
rb_sysopen(const char *fname, int modenum, mode_t perm)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
#ifdef O_BINARY
|
#ifdef O_BINARY
|
||||||
flags |= O_BINARY;
|
modenum |= O_BINARY;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fd = rb_sysopen_internal(fname, flags, mode);
|
fd = rb_sysopen_internal(fname, modenum, perm);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
if (errno == EMFILE || errno == ENFILE) {
|
if (errno == EMFILE || errno == ENFILE) {
|
||||||
rb_gc();
|
rb_gc();
|
||||||
fd = rb_sysopen_internal(fname, flags, mode);
|
fd = rb_sysopen_internal(fname, modenum, perm);
|
||||||
}
|
}
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
rb_sys_fail(fname);
|
rb_sys_fail(fname);
|
||||||
@ -4862,14 +4862,14 @@ rb_f_open(int argc, VALUE *argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_io_open(VALUE filename, VALUE mode, VALUE vperm, VALUE opt)
|
rb_io_open(VALUE filename, VALUE vmode, VALUE vperm, VALUE opt)
|
||||||
{
|
{
|
||||||
VALUE cmd;
|
VALUE cmd;
|
||||||
int modenum, flags;
|
int modenum, flags;
|
||||||
convconfig_t convconfig;
|
convconfig_t convconfig;
|
||||||
mode_t perm;
|
mode_t perm;
|
||||||
|
|
||||||
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
|
rb_io_extract_modeenc(&vmode, opt, &modenum, &flags, &convconfig);
|
||||||
perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
|
perm = NIL_P(vperm) ? 0666 : NUM2UINT(vperm);
|
||||||
|
|
||||||
if (!NIL_P(cmd = check_pipe_command(filename))) {
|
if (!NIL_P(cmd = check_pipe_command(filename))) {
|
||||||
@ -5546,7 +5546,7 @@ rb_io_stdio_file(rb_io_t *fptr)
|
|||||||
static VALUE
|
static VALUE
|
||||||
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
||||||
{
|
{
|
||||||
VALUE fnum, mode;
|
VALUE fnum, vmode;
|
||||||
rb_io_t *fp;
|
rb_io_t *fp;
|
||||||
int fd, flags, modenum = O_RDONLY;
|
int fd, flags, modenum = O_RDONLY;
|
||||||
convconfig_t convconfig;
|
convconfig_t convconfig;
|
||||||
@ -5555,12 +5555,12 @@ rb_io_initialize(int argc, VALUE *argv, VALUE io)
|
|||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
|
|
||||||
opt = pop_last_hash(&argc, &argv);
|
opt = pop_last_hash(&argc, &argv);
|
||||||
rb_scan_args(argc, argv, "11", &fnum, &mode);
|
rb_scan_args(argc, argv, "11", &fnum, &vmode);
|
||||||
rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig);
|
rb_io_extract_modeenc(&vmode, opt, &modenum, &flags, &convconfig);
|
||||||
|
|
||||||
fd = NUM2INT(fnum);
|
fd = NUM2INT(fnum);
|
||||||
UPDATE_MAXFD(fd);
|
UPDATE_MAXFD(fd);
|
||||||
if (NIL_P(mode)) {
|
if (NIL_P(vmode)) {
|
||||||
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
#if defined(HAVE_FCNTL) && defined(F_GETFL)
|
||||||
modenum = fcntl(fd, F_GETFL);
|
modenum = fcntl(fd, F_GETFL);
|
||||||
if (modenum == -1) rb_sys_fail(0);
|
if (modenum == -1) rb_sys_fail(0);
|
||||||
@ -6726,7 +6726,7 @@ static void
|
|||||||
open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
||||||
{
|
{
|
||||||
VALUE opt, v;
|
VALUE opt, v;
|
||||||
VALUE mode, perm;
|
VALUE vmode, vperm;
|
||||||
|
|
||||||
FilePathValue(argv[0]);
|
FilePathValue(argv[0]);
|
||||||
arg->io = 0;
|
arg->io = 0;
|
||||||
@ -6753,15 +6753,15 @@ open_key_args(int argc, VALUE *argv, struct foreach_arg *arg)
|
|||||||
arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
|
arg->io = rb_io_open_with_args(RARRAY_LEN(args), RARRAY_PTR(args));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mode = Qnil;
|
vmode = Qnil;
|
||||||
perm = INT2NUM(O_RDONLY);
|
vperm = INT2NUM(O_RDONLY);
|
||||||
v = rb_hash_aref(opt, sym_mode);
|
v = rb_hash_aref(opt, sym_mode);
|
||||||
if (!NIL_P(v))
|
if (!NIL_P(v))
|
||||||
mode = v;
|
vmode = v;
|
||||||
v = rb_hash_aref(opt, sym_perm);
|
v = rb_hash_aref(opt, sym_perm);
|
||||||
if (!NIL_P(v))
|
if (!NIL_P(v))
|
||||||
perm = v;
|
vperm = v;
|
||||||
arg->io = rb_io_open(argv[0], mode, perm, opt);
|
arg->io = rb_io_open(argv[0], vmode, vperm, opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
@ -7281,13 +7281,13 @@ copy_stream_body(VALUE arg)
|
|||||||
src_io = rb_check_convert_type(stp->src, T_FILE, "IO", "to_io");
|
src_io = rb_check_convert_type(stp->src, T_FILE, "IO", "to_io");
|
||||||
if (NIL_P(src_io)) {
|
if (NIL_P(src_io)) {
|
||||||
VALUE args[2];
|
VALUE args[2];
|
||||||
int flags = O_RDONLY;
|
int modenum = O_RDONLY;
|
||||||
#ifdef O_NOCTTY
|
#ifdef O_NOCTTY
|
||||||
flags |= O_NOCTTY;
|
modenum |= O_NOCTTY;
|
||||||
#endif
|
#endif
|
||||||
FilePathValue(stp->src);
|
FilePathValue(stp->src);
|
||||||
args[0] = stp->src;
|
args[0] = stp->src;
|
||||||
args[1] = INT2NUM(flags);
|
args[1] = INT2NUM(modenum);
|
||||||
src_io = rb_class_new_instance(2, args, rb_cFile);
|
src_io = rb_class_new_instance(2, args, rb_cFile);
|
||||||
stp->src = src_io;
|
stp->src = src_io;
|
||||||
stp->close_src = 1;
|
stp->close_src = 1;
|
||||||
@ -7309,13 +7309,13 @@ copy_stream_body(VALUE arg)
|
|||||||
dst_io = rb_check_convert_type(stp->dst, T_FILE, "IO", "to_io");
|
dst_io = rb_check_convert_type(stp->dst, T_FILE, "IO", "to_io");
|
||||||
if (NIL_P(dst_io)) {
|
if (NIL_P(dst_io)) {
|
||||||
VALUE args[3];
|
VALUE args[3];
|
||||||
int flags = O_WRONLY|O_CREAT|O_TRUNC;
|
int modenum = O_WRONLY|O_CREAT|O_TRUNC;
|
||||||
#ifdef O_NOCTTY
|
#ifdef O_NOCTTY
|
||||||
flags |= O_NOCTTY;
|
modenum |= O_NOCTTY;
|
||||||
#endif
|
#endif
|
||||||
FilePathValue(stp->dst);
|
FilePathValue(stp->dst);
|
||||||
args[0] = stp->dst;
|
args[0] = stp->dst;
|
||||||
args[1] = INT2NUM(flags);
|
args[1] = INT2NUM(modenum);
|
||||||
args[2] = INT2FIX(0600);
|
args[2] = INT2FIX(0600);
|
||||||
dst_io = rb_class_new_instance(3, args, rb_cFile);
|
dst_io = rb_class_new_instance(3, args, rb_cFile);
|
||||||
stp->dst = dst_io;
|
stp->dst = dst_io;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user