diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-06 15:10:43 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-10-06 15:10:43 +0000 |
commit | 3fae917fdc49fe6ea56b8e54095376c153344694 (patch) | |
tree | 20100c099ceb35436bc7f58767833eb67e15848a /io.c | |
parent | a8c1615f32012783d62109c6f7ed9c7ca144f856 (diff) | |
download | ruby-3fae917fdc49fe6ea56b8e54095376c153344694.tar.gz ruby-3fae917fdc49fe6ea56b8e54095376c153344694.tar.xz ruby-3fae917fdc49fe6ea56b8e54095376c153344694.zip |
* io.c (rb_io_s_sysopen): preserve path in the buffer allocated by
ALLOCA_N() to prevent modification. [ruby-dev:24438]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7002 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -2572,11 +2572,11 @@ rb_file_sysopen_internal(io, fname, flags, mode) MakeOpenFile(io, fptr); - fd = rb_sysopen(fname, flags, mode); + fptr->path = strdup(fname); m = rb_io_modenum_mode(flags); fptr->mode = rb_io_modenum_flags(flags); + fd = rb_sysopen(fptr->path, flags, mode); fptr->f = rb_fdopen(fd, m); - fptr->path = strdup(fname); return io; } @@ -3007,12 +3007,11 @@ rb_open_file(argc, argv, io) VALUE io; { VALUE fname, vmode, perm; - char *path, *mode; + char *mode; int flags, fmode; rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); FilePathValue(fname); - path = RSTRING(fname)->ptr; if (FIXNUM_P(vmode) || !NIL_P(perm)) { if (FIXNUM_P(vmode)) { @@ -3024,7 +3023,7 @@ rb_open_file(argc, argv, io) } fmode = NIL_P(perm) ? 0666 : NUM2INT(perm); - rb_file_sysopen_internal(io, path, flags, fmode); + rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode); } else { mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode); @@ -3079,6 +3078,7 @@ rb_io_s_sysopen(argc, argv) { VALUE fname, vmode, perm; int flags, fmode, fd; + char *path; rb_scan_args(argc, argv, "12", &fname, &vmode, &perm); FilePathValue(fname); @@ -3092,7 +3092,9 @@ rb_io_s_sysopen(argc, argv) if (NIL_P(perm)) fmode = 0666; else fmode = NUM2INT(perm); - fd = rb_sysopen(RSTRING(fname)->ptr, flags, fmode); + path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1); + strcpy(path, RSTRING(fname)->ptr); + fd = rb_sysopen(path, flags, fmode); return INT2NUM(fd); } |