src/java.base/windows/native/libjava/io_util_md.h
author ihse
Tue, 13 Feb 2018 10:37:33 +0100
branchihse-remove-mapfiles-branch
changeset 56106 40e61db323c2
parent 47235 9ef10c6e67b8
child 56721 01b558efd286
permissions -rw-r--r--
First stab at removing mapfiles.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
56106
40e61db323c2 First stab at removing mapfiles.
ihse
parents: 47235
diff changeset
     2
 * Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
/*
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    30
 * Macros to use the right data type for file descriptors
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    31
 */
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    32
#define FD jlong
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    33
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    34
/*
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    35
 * Prototypes for functions in io_util_md.c called from io_util.c,
28868
445be2b2eae8 8072611: (process) ProcessBuilder redirecting output to file should work with long file names (win)
stuefe
parents: 25859
diff changeset
    36
 * FileDescriptor.c, FileInputStream.c, FileOutputStream.c,
445be2b2eae8 8072611: (process) ProcessBuilder redirecting output to file should work with long file names (win)
stuefe
parents: 25859
diff changeset
    37
 * ProcessImpl_md.c
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
WCHAR* getPrefixed(const WCHAR* path, int pathlen);
6885
5605d7d60c9c 6983520: java/io/pathNames/GeneralWin32.java fails with jdk7-b108 (win)
alanb
parents: 5506
diff changeset
    42
WCHAR* currentDir(int di);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
int currentDirLength(const WCHAR* path, int pathlen);
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    44
int handleAvailable(FD fd, jlong *pbytes);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    45
int handleSync(FD fd);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    46
int handleSetLength(FD fd, jlong length);
34890
0e8281ef3550 4823133: RandomAccessFile.length() is not thread-safe
vtewari
parents: 28868
diff changeset
    47
jlong handleGetLength(FD fd);
16476
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    48
JNIEXPORT jint handleRead(FD fd, void *buf, jint len);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    49
jint handleWrite(FD fd, const void *buf, jint len);
e269be167fae 8001334: Remove use of JVM_* functions from java.io code
dxu
parents: 14342
diff changeset
    50
jint handleAppend(FD fd, const void *buf, jint len);
47235
9ef10c6e67b8 8187631: Refactor FileDescriptor close implementation
rriggs
parents: 47216
diff changeset
    51
void handleClose(JNIEnv *env, jobject this, jfieldID fid);
9ef10c6e67b8 8187631: Refactor FileDescriptor close implementation
rriggs
parents: 47216
diff changeset
    52
void fileDescriptorClose(JNIEnv *env, jobject this);
56106
40e61db323c2 First stab at removing mapfiles.
ihse
parents: 47235
diff changeset
    53
JNIEXPORT jlong handleLseek(FD fd, jlong offset, jint whence);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Returns an opaque handle to file named by "path".  If an error occurs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * returns -1 and an exception is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 */
56106
40e61db323c2 First stab at removing mapfiles.
ihse
parents: 47235
diff changeset
    59
JNIEXPORT FD winFileHandleOpen(JNIEnv *env, jstring path, int flags);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * Macros to set/get fd from the java.io.FileDescriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * If GetObjectField returns null, SET_FD will stop and GET_FD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * will simply return -1 to avoid crashing VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define SET_FD(this, fd, fid) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        (*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
#define GET_FD(this, fid) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    ((*env)->GetObjectField(env, (this), (fid)) == NULL) ? \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      -1 : (*env)->GetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * Macros to set/get fd when inside java.io.FileDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
/*
7515
43202796198e 6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents: 6885
diff changeset
    80
 * Route the routines away from VM
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 */
7515
43202796198e 6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents: 6885
diff changeset
    82
#define IO_Append handleAppend
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#define IO_Write handleWrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
#define IO_Sync handleSync
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
#define IO_Read handleRead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
#define IO_Lseek handleLseek
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define IO_Available handleAvailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define IO_SetLength handleSetLength
34890
0e8281ef3550 4823133: RandomAccessFile.length() is not thread-safe
vtewari
parents: 28868
diff changeset
    89
#define IO_GetLength handleGetLength
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Setting the handle field in Java_java_io_FileDescriptor_set for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * standard handles stdIn, stdOut, stdErr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#define SET_HANDLE(fd) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
if (fd == 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    return (jlong)GetStdHandle(STD_INPUT_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
} else if (fd == 1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
} else if (fd == 2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    return (jlong)GetStdHandle(STD_ERROR_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
} else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    return (jlong)-1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
} \
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
/* INVALID_FILE_ATTRIBUTES is not defined in VC++6.0's header files but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * in later release. Keep here just in case someone is still using VC++6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
#ifndef INVALID_FILE_ATTRIBUTES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
#endif