use of org.graalvm.word.SignedWord in project graal by oracle.
the class PosixUtils method readSingle.
static int readSingle(FileDescriptor fd) throws IOException {
CCharPointer retPtr = StackValue.get(SizeOf.get(CCharPointer.class));
int handle = PosixUtils.getFDHandle(fd);
SignedWord nread = read(handle, retPtr, WordFactory.unsigned(1));
if (nread.equal(0)) {
// EOF
return -1;
} else if (nread.equal(-1)) {
throw new IOException(lastErrorString("Read error"));
}
return retPtr.read() & 0xFF;
}
use of org.graalvm.word.SignedWord in project graal by oracle.
the class PosixUtils method writeSingle.
@SuppressWarnings("unused")
static void writeSingle(FileDescriptor fd, int b, boolean append) throws IOException {
SignedWord n;
int handle = Util_java_io_FileDescriptor.getFD(fd);
if (handle == -1) {
throw new IOException("Stream Closed");
}
CCharPointer bufPtr = StackValue.get(SizeOf.get(CCharPointer.class));
bufPtr.write((byte) b);
// the append parameter is disregarded
n = write(handle, bufPtr, WordFactory.unsigned(1));
if (n.equal(-1)) {
throw new IOException(lastErrorString("Write error"));
}
}
use of org.graalvm.word.SignedWord in project graal by oracle.
the class PosixJavaIOSubstitutions method skip.
@Substitute
public long skip(long n) throws IOException {
SignedWord cur = WordFactory.zero();
SignedWord end = WordFactory.zero();
int handle = PosixUtils.getFDHandle(fd);
if ((cur = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) {
throw new IOException(lastErrorString("Seek error"));
} else if ((end = lseek(handle, WordFactory.signed(n), SEEK_CUR())).equal(WordFactory.signed(-1))) {
throw new IOException(lastErrorString("Seek error"));
}
return end.subtract(cur).rawValue();
}
use of org.graalvm.word.SignedWord in project graal by oracle.
the class PosixJavaIOSubstitutions method getFilePointer.
@Substitute
public long getFilePointer() throws IOException {
SignedWord ret;
int handle = PosixUtils.getFDHandle(fd);
if ((ret = lseek(handle, WordFactory.zero(), SEEK_CUR())).equal(WordFactory.signed(-1))) {
throw new IOException(lastErrorString("Seek failed"));
}
return ret.rawValue();
}
use of org.graalvm.word.SignedWord in project graal by oracle.
the class PosixJavaLangSubstitutions method writeEntirely.
@Uninterruptible(reason = "Called from uninterruptible code.")
static SignedWord writeEntirely(int fd, PointerBase buf, UnsignedWord count) {
Pointer ptr = WordFactory.pointer(buf.rawValue());
final Pointer end = ptr.add(count);
SignedWord written;
do {
Errno.set_errno(0);
written = UnistdNoTransitions.write(fd, ptr, end.subtract(ptr));
if (written.greaterThan(0)) {
ptr = ptr.add((int) written.rawValue());
}
} while (ptr.notEqual(end) && (written.notEqual(-1) || Errno.errno() == Errno.EINTR()));
if (ptr.notEqual(buf)) {
return WordFactory.signed(ptr.rawValue() - buf.rawValue());
}
return written;
}
Aggregations