summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c35
1 files changed, 18 insertions, 17 deletions
diff --git a/io.c b/io.c
index 0c5172f..b59b39c 100644
--- a/io.c
+++ b/io.c
@@ -3256,7 +3256,7 @@ rb_io_s_popen(argc, argv, klass)
mode = rb_io_modenum_mode(FIX2INT(pmode));
}
else {
- mode = rb_io_flags_mode(rb_io_mode_flags(StringValuePtr(pmode)));
+ mode = rb_io_flags_mode(rb_io_mode_flags(StringValueCStr(pmode)));
}
SafeStringValue(pname);
port = pipe_open(pname, 0, mode);
@@ -3284,12 +3284,13 @@ rb_open_file(argc, argv, io)
VALUE io;
{
VALUE fname, vmode, perm;
- char *mode;
+ char *path, *mode;
int flags, fmode;
rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
SafeStringValue(fname);
+ path = StringValueCStr(fname);
if (FIXNUM_P(vmode) || !NIL_P(perm)) {
if (FIXNUM_P(vmode)) {
flags = FIX2INT(vmode);
@@ -3300,11 +3301,11 @@ rb_open_file(argc, argv, io)
}
fmode = NIL_P(perm) ? 0666 : NUM2INT(perm);
- rb_file_sysopen_internal(io, RSTRING(fname)->ptr, flags, fmode);
+ rb_file_sysopen_internal(io, path, flags, fmode);
}
else {
- mode = NIL_P(vmode) ? "r" : StringValuePtr(vmode);
- rb_file_open_internal(io, RSTRING(fname)->ptr, mode);
+ mode = NIL_P(vmode) ? "r" : StringValueCStr(vmode);
+ rb_file_open_internal(io, path, mode);
}
return io;
}
@@ -3657,7 +3658,7 @@ rb_io_reopen(argc, argv, file)
}
if (!NIL_P(nmode)) {
- fptr->mode = rb_io_mode_flags(StringValuePtr(nmode));
+ fptr->mode = rb_io_mode_flags(StringValueCStr(nmode));
}
if (fptr->path) {
@@ -3665,7 +3666,7 @@ rb_io_reopen(argc, argv, file)
fptr->path = 0;
}
- fptr->path = strdup(RSTRING(fname)->ptr);
+ fptr->path = strdup(StringValueCStr(fname));
mode = rb_io_flags_mode(fptr->mode);
if (!fptr->f) {
fptr->f = rb_fopen(fptr->path, mode);
@@ -3676,16 +3677,16 @@ rb_io_reopen(argc, argv, file)
return file;
}
- if (freopen(RSTRING(fname)->ptr, mode, fptr->f) == 0) {
+ if (freopen(fptr->path, mode, fptr->f) == 0) {
rb_sys_fail(fptr->path);
}
#ifdef USE_SETVBUF
if (setvbuf(fptr->f, NULL, _IOFBF, 0) != 0)
- rb_warn("setvbuf() can't be honoured for %s", RSTRING(fname)->ptr);
+ rb_warn("setvbuf() can't be honoured for %s", fptr->path);
#endif
if (fptr->f2) {
- if (freopen(RSTRING(fname)->ptr, "w", fptr->f2) == 0) {
+ if (freopen(fptr->path, "w", fptr->f2) == 0) {
rb_sys_fail(fptr->path);
}
}
@@ -4234,7 +4235,7 @@ rb_io_initialize(argc, argv, io)
}
else {
SafeStringValue(mode);
- flags = rb_io_mode_modenum(RSTRING(mode)->ptr);
+ flags = rb_io_mode_modenum(StringValueCStr(mode));
}
}
else {
@@ -4404,7 +4405,7 @@ next_argv()
retry:
if (RARRAY(rb_argv)->len > 0) {
filename = rb_ary_shift(rb_argv);
- fn = StringValuePtr(filename);
+ fn = StringValueCStr(filename);
if (strlen(fn) == 1 && fn[0] == '-') {
current_file = rb_stdin;
if (ruby_inplace_mode) {
@@ -5065,7 +5066,7 @@ rb_f_syscall(argc, argv)
if (!NIL_P(v)) {
StringValue(v);
rb_str_modify(v);
- arg[i] = (unsigned long)RSTRING(v)->ptr;
+ arg[i] = (unsigned long)StringValueCStr(v);
}
else {
arg[i] = (unsigned long)NUM2LONG(*argv);
@@ -5273,7 +5274,7 @@ rb_io_s_foreach(argc, argv)
else if (!NIL_P(arg.sep)) {
StringValue(arg.sep);
}
- arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_foreach, (VALUE)&arg, rb_io_close, arg.io);
@@ -5312,7 +5313,7 @@ rb_io_s_readlines(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc - 1;
- arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
return rb_ensure(io_s_readlines, (VALUE)&arg, rb_io_close, arg.io);
}
@@ -5350,7 +5351,7 @@ rb_io_s_read(argc, argv, io)
SafeStringValue(fname);
arg.argc = argc ? 1 : 0;
- arg.io = rb_io_open(RSTRING(fname)->ptr, "r");
+ arg.io = rb_io_open(StringValueCStr(fname), "r");
if (NIL_P(arg.io)) return Qnil;
if (!NIL_P(offset)) {
rb_io_seek(arg.io, offset, SEEK_SET);
@@ -5626,7 +5627,7 @@ opt_i_set(val)
StringValue(val);
if (ruby_inplace_mode) free(ruby_inplace_mode);
ruby_inplace_mode = 0;
- ruby_inplace_mode = strdup(RSTRING(val)->ptr);
+ ruby_inplace_mode = strdup(StringValueCStr(val));
}
/*