3909N/A * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 0N/A/* If this returns NULL then an exception is pending */ 2919N/A/* Returns the working directory for the given drive, or NULL */ 2919N/A // verify drive is valid as _wgetdcwd in the VC++ 2010 runtime 2919N/A // library does not handle invalid drives. 0N/A/* We cache the length of current working dir here to avoid 0N/A calling _wgetcwd() every time we need to resolve a relative 0N/A path. This piece of code needs to be revisited if chdir 0N/A makes its way into java runtime. 0N/A if ((d >= L
'a') && (d <= L
'z'))
di = d - L
'a' +
1;
0N/A else if ((d >= L
'A') && (d <= L
'Z'))
di = d - L
'A' +
1;
0N/A else return 0;
/* invalid drive name. */ 0N/A //relative to both drive and directory 384N/A The "abpathlen" is the size of the buffer needed by _wfullpath. If the 384N/A "path" is a relative path, it is "the length of the current dir" + "the 384N/A length of the path", if it's "absolute" already, it's the same as 384N/A pathlen which is the length of "path". 384N/A /* Collapse instances of "foo\.." and ensure absoluteness before 384N/A going down to prefixing. 384N/A /* _wfullpath fails if the pathlength exceeds 32k wchar. 384N/A Instead of doing more fancy things we simply copy the 384N/A ps into the return buffer, the subsequent win32 API will 384N/A probably fail with FileNotFoundException, which is expected 0N/A/* If this returns NULL then an exception is pending */ 384N/A int max_path =
248;
/* CreateDirectoryW() has the limit of 248 */ 0N/A (
ps[0] == L
'\\' &&
ps[
1] == L
'\\' ||
//UNC 384N/A ps[
1] == L
':' &&
ps[
2] == L
'\\'))
//absolute 0N/A /* If the path came in as a relative path, need to verify if 0N/A its absolute form is bigger than max_path or not, if yes 0N/A need to (1)convert it to absolute and (2)prefix. This is 0N/A obviously a burden to all relative paths (The current dir/len 384N/A for "drive & directory" relative path is cached, so we only 0N/A calculate it once but for "drive-relative path we call 0N/A _wgetdcwd() and wcslen() everytime), but a hit we have 0N/A to take if we want to support relative path beyond max_path. 0N/A There is no way to predict how long the absolute path will be 0N/A (therefor allocate the sufficient memory block) before calling 0N/A _wfullpath(), we have to get the length of "current" dir first. 0N/A /* Note: O_TRUNC overrides O_CREAT */ 0N/A /* Exception already pending */ 0N/A "Too many open files");
0N/A/* These are functions that use a handle fd instead of the 0N/A old C style int fd as is used in HPI layer */ 0N/A /* Handle is for keyboard or pipe */ 0N/A /* Handle is for regular file */ 0N/A /* This is used for available on non-seekable devices 0N/A * (like both named and anonymous pipes, such as pipes 0N/A * connected to an exec'd process). 0N/A * Standard Input is a special case. 0N/A /* PeekNamedPipe fails when at EOF. In that case we 0N/A * simply make *pbytes = 0 which is consistent with the 0N/A * behavior we get on Solaris when an fd is at EOF. 0N/A * The only alternative is to raise and Exception, 0N/A * which isn't really warranted. 0N/A /* Construct an array of input records in the console buffer */ 0N/A /* lpBuffer must fit into 64K or else PeekConsoleInput fails */ 0N/A /* Examine input records for the number of bytes available */ 0N/A * This is documented to succeed on read-only files, but Win32's 0N/A * FlushFileBuffers functions fails with "access denied" in such a 0N/A * case. So we only signal an error if the error is *not* "access 0N/A * From the documentation: 0N/A * On Windows NT, the function FlushFileBuffers fails if hFile 0N/A * is a handle to console output. That is because console 0N/A * output is not buffered. The function returns FALSE, and 0N/A * GetLastError returns ERROR_INVALID_HANDLE. 0N/A * On the other hand, on Win95, it returns without error. I cannot 0N/A * assume that 0, 1, and 2 are console, because if someone closes 0N/A * System.out and then opens a file, they might get file descriptor 0N/A * 1. An error on *that* version of 1 should be reported, whereas 0N/A * an error on System.out (which was the original 1) should be 0N/A * ignored. So I use isatty() to ensure that such an error was due 0N/A * to this bogosity, and if it was, I ignore the error. 0N/A buf,
/* address to put data */ 0N/A len,
/* number of bytes to read */ 0N/A /* Set the fd to -1 before closing it so that the timing window 0N/A * of other threads using the wrong fd (closed but recycled fd, 0N/A * that gets re-opened with some other filename) is reduced. 0N/A * Practically the chance of its occurance is low, however, we are 0N/A * taking extra precaution over here.