[pypy-svn] r46493 - pypy/dist/pypy/translator/jvm/src/pypy
antocuni at codespeak.net
antocuni at codespeak.net
Wed Sep 12 12:17:43 CEST 2007
Author: antocuni
Date: Wed Sep 12 12:17:42 2007
New Revision: 46493
Modified:
pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
Log:
ll_os_lseek for jvm
Modified: pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java (original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/ll_os.java Wed Sep 12 12:17:42 2007
@@ -10,6 +10,7 @@
public abstract void write(String buffer);
public abstract String read(int count);
public abstract void close();
+ public abstract RandomAccessFile getFile();
}
class PrintStreamWrapper extends FileWrapper
@@ -36,6 +37,11 @@
{
ll_os.throwOSError(PyPy.EBADF, "Cannot close stdout or stderr");
}
+
+ public RandomAccessFile getFile()
+ {
+ return null;
+ }
}
class InputStreamWrapper extends FileWrapper
@@ -69,6 +75,11 @@
{
ll_os.throwOSError(PyPy.EBADF, "Cannot close stdin");
}
+
+ public RandomAccessFile getFile()
+ {
+ return null;
+ }
}
class RandomAccessFileWrapper extends FileWrapper
@@ -125,6 +136,11 @@
ll_os.throwOSError(PyPy.EIO, e.getMessage());
}
}
+
+ public RandomAccessFile getFile()
+ {
+ return this.file;
+ }
}
@@ -147,6 +163,10 @@
private static final int S_IFDIR = 16384;
private static final int S_IFREG = 32768;
+ private static final int SEEK_SET = 0;
+ private static final int SEEK_CUR = 1;
+ private static final int SEEK_END = 2;
+
private static int fdcount;
private static Map<Integer, FileWrapper> FileDescriptors = new HashMap<Integer, FileWrapper>();
private static Map<Integer, String> ErrorMessages = new HashMap<Integer, String>();
@@ -240,6 +260,36 @@
return ll_os_read(fd, (int)count);
}
+ public static long ll_os_lseek(int fd, long offset, int whence)
+ {
+ FileWrapper wrapper = getfd(fd);
+ RandomAccessFile file = wrapper.getFile();
+ if (file == null)
+ throwOSError(PyPy.ESPIPE, "Illegal seek");
+
+ long pos = 0;
+ try {
+ switch(whence)
+ {
+ case SEEK_SET:
+ pos = offset;
+ break;
+ case SEEK_CUR:
+ pos = file.getFilePointer() + offset;
+ break;
+ case SEEK_END:
+ pos = file.length() + offset;
+ break;
+ }
+ file.seek(pos);
+ }
+ catch(IOException e) {
+ throwOSError(PyPy.ESPIPE, e.getMessage());
+ }
+
+ return pos;
+ }
+
public static StatResult ll_os_lstat(String path)
{
return ll_os_stat(path); // XXX
More information about the Pypy-commit
mailing list