static public Method

IO.sysopen(...)

IO.sysopen(path, [mode, [perm]])   fixnum

Opens the given path, returning the underlying file descriptor as a Fixnum.

IO.sysopen("testfile")   #=> 3

Source Code

/*
*  call-seq:
*     IO.sysopen(path, [mode, [perm]])  => fixnum
*  
*  Opens the given path, returning the underlying file descriptor as a
*  <code>Fixnum</code>.
*     
*     IO.sysopen("testfile")   #=> 3
*     
*/

static VALUE
rb_io_s_sysopen(argc, argv)
   int argc;
   VALUE *argv;
{
   VALUE fname, vmode, perm;
   int flags, fmode, fd;
   char *path;

   rb_scan_args(argc, argv, "12", &fname, &vmode, &perm);
   SafeStringValue(fname);

   if (NIL_P(vmode)) flags = O_RDONLY;
   else if (FIXNUM_P(vmode)) flags = FIX2INT(vmode);
   else {
       SafeStringValue(vmode);
       flags = rb_io_mode_modenum(RSTRING(vmode)->ptr);
   }
   if (NIL_P(perm)) fmode = 0666;
   else             fmode = NUM2INT(perm);

   path = ALLOCA_N(char, strlen(RSTRING(fname)->ptr)+1);
   strcpy(path, RSTRING(fname)->ptr);
   fd = rb_sysopen(path, flags, fmode);
   return INT2NUM(fd);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.