public final String toString() { return description(); } public static OpenFlags valueOf(long value) {
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();
private void setBinmode() { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { if (fptr.readconv != null) fptr.readconv.binmode(); if (fptr.writeconv != null) fptr.writeconv.binmode(); fptr.setBinmode(); fptr.clearTextMode(); fptr.writeconvPreEcflags &= ~EConvFlags.NEWLINE_DECORATOR_MASK; if (OpenFlags.O_BINARY.defined()) { // TODO: Windows // if (fptr.readconv == null) { // SET_BINARY_MODE_WITH_SEEK_CUR(fptr); // } // else { // TODO: setmode O_BINARY means what via NIO? // setmode(fptr->fd, O_BINARY); // } } } finally { if (locked) fptr.unlock(); } }
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;
private void setBinmode() { OpenFile fptr; fptr = getOpenFileChecked(); boolean locked = fptr.lock(); try { if (fptr.readconv != null) fptr.readconv.binmode(); if (fptr.writeconv != null) fptr.writeconv.binmode(); fptr.setBinmode(); fptr.clearTextMode(); fptr.writeconvPreEcflags &= ~EConvFlags.NEWLINE_DECORATOR_MASK; if (OpenFlags.O_BINARY.defined()) { // TODO: Windows // if (fptr.readconv == null) { // SET_BINARY_MODE_WITH_SEEK_CUR(fptr); // } // else { // TODO: setmode O_BINARY means what via NIO? // setmode(fptr->fd, O_BINARY); // } } } finally { if (locked) fptr.unlock(); } }
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;
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 final String toString() { return description(); } public static OpenFlags valueOf(long value) {
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; }
} else { return OpenFlags.O_RDWR.intValue();
public final String toString() { return description(); } public static OpenFlags valueOf(long value) {
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; }
} else { return OpenFlags.O_RDWR.intValue();
int mode = OpenFlags.O_WRONLY.intValue() | OpenFlags.O_CREAT.intValue(); if ( OpenFlags.O_BINARY.defined() ) { if ( binary ) mode |= OpenFlags.O_BINARY.intValue(); if ( offset == context.nil ) mode |= OpenFlags.O_TRUNC.intValue(); optHash.op_aset(context, modeSym, runtime.newFixnum(mode)); final RubyIO io = (RubyIO) _io; if ( ! OpenFlags.O_BINARY.defined() ) { if ( binary ) io.binmode();
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; }