jdk/src/windows/native/java/io/io_util_md.h
author martin
Mon, 10 Mar 2008 14:32:51 -0700
changeset 45 307f564057c1
parent 2 90ce3da70b43
child 715 f16baef3a20e
permissions -rw-r--r--
6631362: Nuke io_util_md.c:handleFileSizeFD (win) Reviewed-by: alanb, iris
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
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
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * Prototypes for functions in io_util_md.c called from io_util,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * FileDescriptor.c, FileInputStream.c, FileOutputStream.c
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
WCHAR* getPrefixed(const WCHAR* path, int pathlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
int currentDirLength(const WCHAR* path, int pathlen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
void fileOpen(JNIEnv *env, jobject this, jstring path, jfieldID fid, int flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
int handleAvailable(jlong fd, jlong *pbytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
JNIEXPORT int handleSync(jlong fd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
int handleSetLength(jlong fd, jlong length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
JNIEXPORT size_t handleRead(jlong fd, void *buf, jint len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
JNIEXPORT size_t handleWrite(jlong fd, const void *buf, jint len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
jint handleClose(JNIEnv *env, jobject this, jfieldID fid);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
jlong handleLseek(jlong fd, jlong offset, jint whence);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Returns an opaque handle to file named by "path".  If an error occurs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * returns -1 and an exception is pending.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
jlong winFileHandleOpen(JNIEnv *env, jstring path, int flags);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * Macros to use the right data type for file descriptors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
#define FD jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Macros to set/get fd from the java.io.FileDescriptor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * If GetObjectField returns null, SET_FD will stop and GET_FD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * will simply return -1 to avoid crashing VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
#define SET_FD(this, fd, fid) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        (*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define GET_FD(this, fid) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    ((*env)->GetObjectField(env, (this), (fid)) == NULL) ? \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
      -1 : (*env)->GetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Macros to set/get fd when inside java.io.FileDescriptor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
#define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * Route the routines away from HPI layer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define IO_Write handleWrite
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define IO_Sync handleSync
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define IO_Read handleRead
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define IO_Lseek handleLseek
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define IO_Available handleAvailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
#define IO_SetLength handleSetLength
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Setting the handle field in Java_java_io_FileDescriptor_set for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * standard handles stdIn, stdOut, stdErr
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define SET_HANDLE(fd) \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
if (fd == 0) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    return (jlong)GetStdHandle(STD_INPUT_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
} else if (fd == 1) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
} else if (fd == 2) { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    return (jlong)GetStdHandle(STD_ERROR_HANDLE); \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
} else { \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    return (jlong)-1; \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
} \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/* INVALID_FILE_ATTRIBUTES is not defined in VC++6.0's header files but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * in later release. Keep here just in case someone is still using VC++6.0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#ifndef INVALID_FILE_ATTRIBUTES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#endif