Path: blob/master/src/java.base/windows/native/libjava/io_util_md.h
41119 views
/*1* Copyright (c) 2003, 2020, 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.c,36* ProcessImpl_md.c37*/38WCHAR* pathToNTPath(JNIEnv *env, jstring path, jboolean throwFNFE);39WCHAR* fileToNTPath(JNIEnv *env, jobject file, jfieldID id);40JNIEXPORT WCHAR* getPrefixed(const WCHAR* path, int pathlen);41WCHAR* currentDir(int di);42int currentDirLength(const WCHAR* path, int pathlen);43int handleAvailable(FD fd, jlong *pbytes);44int handleSync(FD fd);45jint handleSetLength(FD fd, jlong length);46jlong handleGetLength(FD fd);47JNIEXPORT jint handleRead(FD fd, void *buf, jint len);48jint handleWrite(FD fd, const void *buf, jint len);49jint handleAppend(FD fd, const void *buf, jint len);50void fileDescriptorClose(JNIEnv *env, jobject this);51JNIEXPORT jlong JNICALL52handleLseek(FD fd, jlong offset, jint whence);5354/*55* Returns an opaque handle to file named by "path". If an error occurs,56* returns -1 and an exception is pending.57*/58FD winFileHandleOpen(JNIEnv *env, jstring path, int flags);5960/*61* Function to get fd from the java.io.FileDescriptor field of an62* object. These functions rely on having an appropriately63* defined object with a FileDescriptor object at the fid offset.64* If the FD object is null, return -1 to avoid crashing VM.65*/66FD getFD(JNIEnv *env, jobject cur, jfieldID fid);6768/*69* Macros to set/get fd when inside java.io.FileDescriptor70*/71#define THIS_FD(obj) (*env)->GetLongField(env, obj, IO_handle_fdID)7273/*74* Route the routines away from VM75*/76#define IO_Append handleAppend77#define IO_Write handleWrite78#define IO_Sync handleSync79#define IO_Read handleRead80#define IO_Lseek handleLseek81#define IO_Available handleAvailable82#define IO_SetLength handleSetLength83#define IO_GetLength handleGetLength8485/*86* Setting the handle field in Java_java_io_FileDescriptor_set for87* standard handles stdIn, stdOut, stdErr88*/89#define SET_HANDLE(fd) \90if (fd == 0) { \91return (jlong)GetStdHandle(STD_INPUT_HANDLE); \92} else if (fd == 1) { \93return (jlong)GetStdHandle(STD_OUTPUT_HANDLE); \94} else if (fd == 2) { \95return (jlong)GetStdHandle(STD_ERROR_HANDLE); \96} else { \97return (jlong)-1; \98} \99100/* INVALID_FILE_ATTRIBUTES is not defined in VC++6.0's header files but101* in later release. Keep here just in case someone is still using VC++6.0102*/103#ifndef INVALID_FILE_ATTRIBUTES104#define INVALID_FILE_ATTRIBUTES ((DWORD)-1)105#endif106107108