27 #include "jni_util.h"
28
29 /*
30 * Macros to use the right data type for file descriptors
31 */
32 #define FD jlong
33
34 /*
35 * Prototypes for functions in io_util_md.c called from io_util.c,
36 * FileDescriptor.c, FileInputStream.c, FileOutputStream.c
37 */
38 WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);
39 WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);
40 WCHAR* getPrefixed(const WCHAR* path, int pathlen);
41 WCHAR* currentDir(int di);
42 int currentDirLength(const WCHAR* path, int pathlen);
43 int handleAvailable(FD fd, jlong *pbytes);
44 int handleSync(FD fd);
45 int handleSetLength(FD fd, jlong length);
46 JNIEXPORT jint handleRead(FD fd, void *buf, jint len);
47 jint handleWrite(FD fd, const void *buf, jint len);
48 jint handleAppend(FD fd, const void *buf, jint len);
49 jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
50 jlong handleLseek(FD fd, jlong offset, jint whence);
51
52 /*
53 * Returns an opaque handle to file named by "path". If an error occurs,
54 * returns -1 and an exception is pending.
55 */
56 FD winFileHandleOpen(JNIEnv *env, jstring path, int flags);
57
58 /*
59 * Macros to set/get fd from the java.io.FileDescriptor.
60 * If GetObjectField returns null, SET_FD will stop and GET_FD
61 * will simply return -1 to avoid crashing VM.
62 */
63 #define SET_FD(this, fd, fid) \
64 if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
65 (*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))
66
67 #define GET_FD(this, fid) \
68 ((*env)->GetObjectField(env, (this), (fid)) == NULL) ? \
69 -1 : (*env)->GetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID)
70
71 /*
72 * Macros to set/get fd when inside java.io.FileDescriptor
73 */
74 #define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)
75
76 /*
77 * Route the routines away from VM
78 */
79 #define IO_Append handleAppend
80 #define IO_Write handleWrite
81 #define IO_Sync handleSync
82 #define IO_Read handleRead
83 #define IO_Lseek handleLseek
84 #define IO_Available handleAvailable
85 #define IO_SetLength handleSetLength
86
87 /*
88 * Setting the handle field in Java_java_io_FileDescriptor_set for
89 * standard handles stdIn, stdOut, stdErr
90 */
91 #define SET_HANDLE(fd) \
92 if (fd == 0) { \
93 return (jlong)GetStdHandle(STD_INPUT_HANDLE); \
94 } else if (fd == 1) { \
95 return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \
96 } else if (fd == 2) { \
97 return (jlong)GetStdHandle(STD_ERROR_HANDLE); \
98 } else { \
99 return (jlong)-1; \
|
27 #include "jni_util.h"
28
29 /*
30 * Macros to use the right data type for file descriptors
31 */
32 #define FD jlong
33
34 /*
35 * Prototypes for functions in io_util_md.c called from io_util.c,
36 * FileDescriptor.c, FileInputStream.c, FileOutputStream.c
37 */
38 WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);
39 WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);
40 WCHAR* getPrefixed(const WCHAR* path, int pathlen);
41 WCHAR* currentDir(int di);
42 int currentDirLength(const WCHAR* path, int pathlen);
43 int handleAvailable(FD fd, jlong *pbytes);
44 int handleSync(FD fd);
45 int handleSetLength(FD fd, jlong length);
46 JNIEXPORT jint handleRead(FD fd, void *buf, jint len);
47 jint handleWrite(JNIEnv *env, jobject this, jfieldID fid,
48 const void *buf, jint len);
49 jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
50 jlong handleLseek(FD fd, jlong offset, jint whence);
51
52 /*
53 * Returns an opaque handle to file named by "path". If an error occurs,
54 * returns -1 and an exception is pending.
55 */
56 FD winFileHandleOpen(JNIEnv *env, jstring path, int flags);
57
58 /*
59 * Macros to set/get fd from the java.io.FileDescriptor.
60 * If GetObjectField returns null, SET_FD will stop and GET_FD
61 * will simply return -1 to avoid crashing VM.
62 */
63 #define SET_FD(this, fd, fid) \
64 if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
65 (*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))
66
67 #define GET_FD(this, fid) \
68 ((*env)->GetObjectField(env, (this), (fid)) == NULL) ? \
69 -1 : (*env)->GetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID)
70
71 /*
72 * Macros to set/get fd when inside java.io.FileDescriptor
73 */
74 #define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)
75
76 /*
77 * Route the routines away from VM
78 */
79 #define IO_Write handleWrite
80 #define IO_Sync handleSync
81 #define IO_Read handleRead
82 #define IO_Lseek handleLseek
83 #define IO_Available handleAvailable
84 #define IO_SetLength handleSetLength
85
86 /*
87 * Setting the handle field in Java_java_io_FileDescriptor_set for
88 * standard handles stdIn, stdOut, stdErr
89 */
90 #define SET_HANDLE(fd) \
91 if (fd == 0) { \
92 return (jlong)GetStdHandle(STD_INPUT_HANDLE); \
93 } else if (fd == 1) { \
94 return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \
95 } else if (fd == 2) { \
96 return (jlong)GetStdHandle(STD_ERROR_HANDLE); \
97 } else { \
98 return (jlong)-1; \
|