2
|
1 |
/*
|
5506
|
2 |
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
|
2
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
#include "jni.h"
|
|
27 |
#include "jni_util.h"
|
|
28 |
|
|
29 |
/*
|
|
30 |
* Prototypes for functions in io_util_md.c called from io_util,
|
|
31 |
* FileDescriptor.c, FileInputStream.c, FileOutputStream.c
|
|
32 |
*/
|
|
33 |
WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);
|
|
34 |
WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);
|
|
35 |
WCHAR* getPrefixed(const WCHAR* path, int pathlen);
|
|
36 |
int currentDirLength(const WCHAR* path, int pathlen);
|
|
37 |
void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
|
|
38 |
int handleAvailable(jlong fd, jlong *pbytes);
|
|
39 |
JNIEXPORT int handleSync(jlong fd);
|
|
40 |
int handleSetLength(jlong fd, jlong length);
|
|
41 |
JNIEXPORT size_t handleRead(jlong fd, void *buf, jint len);
|
|
42 |
JNIEXPORT size_t handleWrite(jlong fd, const void *buf, jint len);
|
|
43 |
jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
|
|
44 |
jlong handleLseek(jlong fd, jlong offset, jint whence);
|
|
45 |
|
|
46 |
/*
|
|
47 |
* Returns an opaque handle to file named by "path". If an error occurs,
|
|
48 |
* returns -1 and an exception is pending.
|
|
49 |
*/
|
|
50 |
jlong winFileHandleOpen(JNIEnv *env, jstring path, int flags);
|
|
51 |
|
|
52 |
/*
|
|
53 |
* Macros to use the right data type for file descriptors
|
|
54 |
*/
|
|
55 |
#define FD jlong
|
|
56 |
|
|
57 |
/*
|
|
58 |
* Macros to set/get fd from the java.io.FileDescriptor.
|
|
59 |
* If GetObjectField returns null, SET_FD will stop and GET_FD
|
|
60 |
* will simply return -1 to avoid crashing VM.
|
|
61 |
*/
|
|
62 |
#define SET_FD(this, fd, fid) \
|
|
63 |
if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
|
|
64 |
(*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))
|
|
65 |
|
|
66 |
#define GET_FD(this, fid) \
|
|
67 |
((*env)->GetObjectField(env, (this), (fid)) == NULL) ? \
|
|
68 |
-1 : (*env)->GetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID)
|
|
69 |
|
|
70 |
/*
|
|
71 |
* Macros to set/get fd when inside java.io.FileDescriptor
|
|
72 |
*/
|
|
73 |
#define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)
|
|
74 |
|
|
75 |
/*
|
|
76 |
* Route the routines away from HPI layer
|
|
77 |
*/
|
|
78 |
#define IO_Write handleWrite
|
|
79 |
#define IO_Sync handleSync
|
|
80 |
#define IO_Read handleRead
|
|
81 |
#define IO_Lseek handleLseek
|
|
82 |
#define IO_Available handleAvailable
|
|
83 |
#define IO_SetLength handleSetLength
|
|
84 |
|
|
85 |
/*
|
|
86 |
* Setting the handle field in Java_java_io_FileDescriptor_set for
|
|
87 |
* standard handles stdIn, stdOut, stdErr
|
|
88 |
*/
|
|
89 |
#define SET_HANDLE(fd) \
|
|
90 |
if (fd == 0) { \
|
|
91 |
return (jlong)GetStdHandle(STD_INPUT_HANDLE); \
|
|
92 |
} else if (fd == 1) { \
|
|
93 |
return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \
|
|
94 |
} else if (fd == 2) { \
|
|
95 |
return (jlong)GetStdHandle(STD_ERROR_HANDLE); \
|
|
96 |
} else { \
|
|
97 |
return (jlong)-1; \
|
|
98 |
} \
|
|
99 |
|
|
100 |
/* INVALID_FILE_ATTRIBUTES is not defined in VC++6.0's header files but
|
|
101 |
* in later release. Keep here just in case someone is still using VC++6.0
|
|
102 |
*/
|
|
103 |
#ifndef INVALID_FILE_ATTRIBUTES
|
|
104 |
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
|
|
105 |
#endif
|