Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/java/io/io_util_md.h
32287 views
/*1* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425#include "jni.h"26#include "jni_util.h"2728/*29* Macros to use the right data type for file descriptors30*/31#define FD jlong3233/*34* Prototypes for functions in io_util_md.c called from io_util.c,35* FileDescriptor.c, FileInputStream.c, FileOutputStream.c36*/37WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);38WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);39WCHAR* getPrefixed(const WCHAR* path, int pathlen);40WCHAR* currentDir(int di);41int currentDirLength(const WCHAR* path, int pathlen);42int handleAvailable(FD fd, jlong *pbytes);43int handleSync(FD fd);44int handleSetLength(FD fd, jlong length);45JNIEXPORT jint handleRead(FD fd, void *buf, jint len);46jint handleWrite(FD fd, const void *buf, jint len);47jint handleAppend(FD fd, const void *buf, jint len);48jint handleClose(JNIEnv *env, jobject this, jfieldID fid);49jlong handleLseek(FD fd, jlong offset, jint whence);5051/*52* Returns an opaque handle to file named by "path". If an error occurs,53* returns -1 and an exception is pending.54*/55FD winFileHandleOpen(JNIEnv *env, jstring path, int flags);5657/*58* Macros to set/get fd from the java.io.FileDescriptor.59* If GetObjectField returns null, SET_FD will stop and GET_FD60* will simply return -1 to avoid crashing VM.61*/62#define SET_FD(this, fd, fid) \63if ((*env)->GetObjectField(env, (this), (fid)) != NULL) \64(*env)->SetLongField(env, (*env)->GetObjectField(env, (this), (fid)), IO_handle_fdID, (fd))6566#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)6970/*71* Macros to set/get fd when inside java.io.FileDescriptor72*/73#define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)7475/*76* Route the routines away from VM77*/78#define IO_Append handleAppend79#define IO_Write handleWrite80#define IO_Sync handleSync81#define IO_Read handleRead82#define IO_Lseek handleLseek83#define IO_Available handleAvailable84#define IO_SetLength handleSetLength8586/*87* Setting the handle field in Java_java_io_FileDescriptor_set for88* standard handles stdIn, stdOut, stdErr89*/90#define SET_HANDLE(fd) \91if (fd == 0) { \92return (jlong)GetStdHandle(STD_INPUT_HANDLE); \93} else if (fd == 1) { \94return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \95} else if (fd == 2) { \96return (jlong)GetStdHandle(STD_ERROR_HANDLE); \97} else { \98return (jlong)-1; \99} \100101/* INVALID_FILE_ATTRIBUTES is not defined in VC++6.0's header files but102* in later release. Keep here just in case someone is still using VC++6.0103*/104#ifndef INVALID_FILE_ATTRIBUTES105#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)106#endif107108109