summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-10 08:44:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-10 08:44:29 +0000
commit997ff23758884944f28a089eaa50ac7eb1c026c6 (patch)
treef99563ed31c2f6a8facc7160cccde602d39af79b /io.c
parentd148ffef297193fe5f6639a8bd8c9ee3d3374479 (diff)
*** empty log message ***
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@397 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/io.c b/io.c
index 439800e40c..ac4771eb81 100644
--- a/io.c
+++ b/io.c
@@ -1088,6 +1088,39 @@ rb_io_mode_flags2(mode)
return flags;
}
+static char*
+rb_io_flags_mode(flags)
+ int flags;
+{
+ static char mode[4];
+ char *p = mode;
+
+ switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
+ case O_RDONLY:
+ *p++ = 'r';
+ break;
+ case O_WRONLY:
+ *p++ = 'w';
+ break;
+ case O_RDWR:
+ *p++ = 'w';
+ *p++ = '+';
+ break;
+ }
+ *p++ = '\0';
+#ifdef O_BINARY
+ if (flags & O_BINARY) {
+ if (mode[1] == '+') {
+ mode[1] = 'b'; mode[2] = '+'; mode[3] = '\0';
+ }
+ else {
+ mode[1] = 'b'; mode[2] = '\0';
+ }
+ }
+#endif
+ return mode;
+}
+
static int
rb_open(fname, flag, mode)
char *fname;
@@ -1171,6 +1204,12 @@ rb_file_sysopen(fname, flags, mode)
char *fname;
int flags, mode;
{
+#ifdef USE_CWGUSI
+ if (mode != 0666) {
+ rb_warn("can't specify file mode on this platform");
+ }
+ return rb_file_open(fname, rb_io_flags_mode(flags));
+#else
OpenFile *fptr;
int fd;
char *m;
@@ -1185,6 +1224,7 @@ rb_file_sysopen(fname, flags, mode)
rb_obj_call_init((VALUE)port);
return (VALUE)port;
+#endif
}
#if defined (NT) || defined(DJGPP) || defined(__CYGWIN32__) || defined(__human68k__)
@@ -1476,33 +1516,7 @@ rb_f_open(argc, argv)
mode = "r";
}
else if (FIXNUM_P(pmode)) {
- int flags = FIX2INT(pmode);
- char *p;
-
- mode = p = ALLOCA_N(char, 4);
- switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
- case O_RDONLY:
- *p++ = 'r';
- break;
- case O_WRONLY:
- *p++ = 'w';
- break;
- case O_RDWR:
- *p++ = 'w';
- *p++ = '+';
- break;
- }
- *p++ = '\0';
-#ifdef O_BINARY
- if (flags & O_BINARY) {
- if (mode[1] == '+') {
- mode[1] = 'b'; mode[2] = '+'; mode[3] = '\0';
- }
- else {
- mode[1] = 'b'; mode[2] = '\0';
- }
- }
-#endif
+ mode = rb_io_flags_mode(FIX2INT(pmode));
}
else {
int len;
@@ -1513,7 +1527,7 @@ rb_f_open(argc, argv)
rb_raise(rb_eArgError, "illegal access mode %s", mode);
}
- port = pipe_open(RSTRING(pname)->ptr, mode);
+ port = pipe_open(RSTRING(pname)->ptr+1, mode);
if (rb_iterator_p()) {
return rb_ensure(rb_yield, port, rb_io_close, port);
}