public static int ioFmodeOflags(int fmode) { int oflags = 0; switch (fmode & OpenFile.READWRITE) { case OpenFile.READABLE: oflags |= OpenFlags.O_RDONLY.intValue(); break; case OpenFile.WRITABLE: oflags |= OpenFlags.O_WRONLY.intValue(); break; case OpenFile.READWRITE: oflags |= OpenFlags.O_RDWR.intValue(); break; } if ((fmode & OpenFile.APPEND) != 0) { oflags |= OpenFlags.O_APPEND.intValue(); } if ((fmode & OpenFile.TRUNC) != 0) { oflags |= OpenFlags.O_TRUNC.intValue(); } if ((fmode & OpenFile.CREATE) != 0) { oflags |= OpenFlags.O_CREAT.intValue(); } if (OpenFlags.O_BINARY.defined()) { if ((fmode & OpenFile.BINMODE) != 0) { oflags |= OpenFlags.O_BINARY.intValue(); } } return oflags; }
public static int ioFmodeOflags(int fmode) { int oflags = 0; switch (fmode & OpenFile.READWRITE) { case OpenFile.READABLE: oflags |= OpenFlags.O_RDONLY.intValue(); break; case OpenFile.WRITABLE: oflags |= OpenFlags.O_WRONLY.intValue(); break; case OpenFile.READWRITE: oflags |= OpenFlags.O_RDWR.intValue(); break; } if ((fmode & OpenFile.APPEND) != 0) { oflags |= OpenFlags.O_APPEND.intValue(); } if ((fmode & OpenFile.TRUNC) != 0) { oflags |= OpenFlags.O_TRUNC.intValue(); } if ((fmode & OpenFile.CREATE) != 0) { oflags |= OpenFlags.O_CREAT.intValue(); } if (OpenFlags.O_BINARY.defined()) { if ((fmode & OpenFile.BINMODE) != 0) { oflags |= OpenFlags.O_BINARY.intValue(); } } return oflags; }
private static String MODE_BINARY(int oflags, String a, String b) { if (OpenFlags.O_BINARY.defined() && (oflags & OpenFlags.O_BINARY.intValue()) != 0) { return b; } return a; }
private static String MODE_BINARY(int oflags, String a, String b) { if (OpenFlags.O_BINARY.defined() && (oflags & OpenFlags.O_BINARY.intValue()) != 0) { return b; } return a; }
public static String ioOflagsModestr(Ruby runtime, int oflags) { int accmode = oflags & (OpenFlags.O_RDONLY.intValue()|OpenFlags.O_WRONLY.intValue()|OpenFlags.O_RDWR.intValue()); if ((oflags & OpenFlags.O_APPEND.intValue()) != 0) { if (accmode == OpenFlags.O_WRONLY.intValue()) { return MODE_BINARY(oflags, "a", "ab"); } if (accmode == OpenFlags.O_RDWR.intValue()) { return MODE_BINARY(oflags, "a+", "ab+"); } } switch (OpenFlags.valueOf(oflags & (OpenFlags.O_RDONLY.intValue()|OpenFlags.O_WRONLY.intValue()|OpenFlags.O_RDWR.intValue()))) { default: throw runtime.newArgumentError("invalid access oflags 0x" + Integer.toHexString(oflags)); case O_RDONLY: return MODE_BINARY(oflags, "r", "rb"); case O_WRONLY: return MODE_BINARY(oflags, "w", "wb"); case O_RDWR: return MODE_BINARY(oflags, "r+", "rb+"); } }
public static String ioOflagsModestr(Ruby runtime, int oflags) { int accmode = oflags & (OpenFlags.O_RDONLY.intValue()|OpenFlags.O_WRONLY.intValue()|OpenFlags.O_RDWR.intValue()); if ((oflags & OpenFlags.O_APPEND.intValue()) != 0) { if (accmode == OpenFlags.O_WRONLY.intValue()) { return MODE_BINARY(oflags, "a", "ab"); } if (accmode == OpenFlags.O_RDWR.intValue()) { return MODE_BINARY(oflags, "a+", "ab+"); } } switch (OpenFlags.valueOf(oflags & (OpenFlags.O_RDONLY.intValue()|OpenFlags.O_WRONLY.intValue()|OpenFlags.O_RDWR.intValue()))) { default: throw runtime.newArgumentError("invalid access oflags 0x" + Integer.toHexString(oflags)); case O_RDONLY: return MODE_BINARY(oflags, "r", "rb"); case O_WRONLY: return MODE_BINARY(oflags, "w", "wb"); case O_RDWR: return MODE_BINARY(oflags, "r+", "rb+"); } }
} else { return OpenFlags.O_RDWR.intValue();
int mode = OpenFlags.O_RDWR.intValue() /*| OpenFlags.O_CREAT.intValue()*/ | OpenFlags.O_EXCL.intValue(); IRubyObject perm = runtime.newFixnum(0600); Tempfile.this.tmpname = tmpname; Tempfile.this.mode = runtime.newFixnum(mode & ~(OpenFlags.O_CREAT.intValue() | OpenFlags.O_EXCL.intValue())); Tempfile.this.opts = opts;
int mode = OpenFlags.O_RDWR.intValue() /*| OpenFlags.O_CREAT.intValue()*/ | OpenFlags.O_EXCL.intValue(); IRubyObject perm = runtime.newFixnum(0600); Tempfile.this.tmpname = tmpname; Tempfile.this.mode = runtime.newFixnum(mode & ~(OpenFlags.O_CREAT.intValue() | OpenFlags.O_EXCL.intValue())); Tempfile.this.opts = opts;
} else { return OpenFlags.O_RDWR.intValue();
} else { return OpenFlags.O_RDWR.intValue();
public int truncate(CharSequence path, long length) { // Windows doesn't have a native truncate() equivalent, but it does have a native ftruncate() equivalent. // In order to call the ftruncate() equivalent, we must convert a path to a FD. We do that by wrapping the // ftruncate() call with open() and close(). // Permissions are ignored since we're not using O_CREAT. int fd = libc().open(path, OpenFlags.O_WRONLY.intValue(), 0); if (fd == -1) { return -1; } if (libc().ftruncate(fd, length) == -1) { return -1; } if (libc().close(fd) == -1) { return -1; } // truncate() returns 0 on success. return 0; }
public int truncate(CharSequence path, long length) { // Windows doesn't have a native truncate() equivalent, but it does have a native ftruncate() equivalent. // In order to call the ftruncate() equivalent, we must convert a path to a FD. We do that by wrapping the // ftruncate() call with open() and close(). // Permissions are ignored since we're not using O_CREAT. int fd = libc().open(path, OpenFlags.O_WRONLY.intValue(), 0); if (fd == -1) { return -1; } if (libc().ftruncate(fd, length) == -1) { return -1; } if (libc().close(fd) == -1) { return -1; } // truncate() returns 0 on success. return 0; }
public int truncate(CharSequence path, long length) { // Windows doesn't have a native truncate() equivalent, but it does have a native ftruncate() equivalent. // In order to call the ftruncate() equivalent, we must convert a path to a FD. We do that by wrapping the // ftruncate() call with open() and close(). // Permissions are ignored since we're not using O_CREAT. int fd = libc().open(path, OpenFlags.O_WRONLY.intValue(), 0); if (fd == -1) { return -1; } if (libc().ftruncate(fd, length) == -1) { return -1; } if (libc().close(fd) == -1) { return -1; } // truncate() returns 0 on success. return 0; }
public static ChannelFD cloexecOpen(Ruby runtime, Sysopen data) { Channel ret = null; if (OpenFlags.O_CLOEXEC.defined()) { data.oflags |= OpenFlags.O_CLOEXEC.intValue(); } else { // #elif defined O_NOINHERIT // flags |= O_NOINHERIT; } PosixShim shim = new PosixShim(runtime); ret = shim.open(runtime.getCurrentDirectory(), data.fname, data.oflags, data.perm); if (ret == null) { data.errno = shim.errno; return null; } ChannelFD fd = new ChannelFD(ret, runtime.getPosix(), runtime.getFilenoUtil()); if (fd.realFileno > 0 && runtime.getPosix().isNative()) { OpenFile.fdFixCloexec(shim, fd.realFileno); } return fd; }
public static ChannelFD cloexecOpen(Ruby runtime, Sysopen data) { Channel ret = null; if (OpenFlags.O_CLOEXEC.defined()) { data.oflags |= OpenFlags.O_CLOEXEC.intValue(); } else { // #elif defined O_NOINHERIT // flags |= O_NOINHERIT; } PosixShim shim = new PosixShim(runtime); ret = shim.open(runtime.getCurrentDirectory(), data.fname, data.oflags, data.perm); if (ret == null) { data.errno = shim.errno; return null; } ChannelFD fd = new ChannelFD(ret, runtime.getPosix(), runtime.getFilenoUtil()); if (fd.realFileno > 0 && runtime.getPosix().isNative()) { OpenFile.fdFixCloexec(shim, fd.realFileno); } return fd; }
oflags = OpenFlags.O_RDONLY.intValue(); else if (!(intmode = TypeConverter.checkIntegerType(context, vmode)).isNil()) oflags = RubyNumeric.num2int(intmode);
oflags = OpenFlags.O_RDONLY.intValue(); else if (!(intmode = TypeConverter.checkIntegerType(context, vmode)).isNil()) oflags = RubyNumeric.num2int(intmode);