/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include "io_util.h"
#include "io_util_md.h"
#include <stdio.h>
#include <wchar.h>
#include <io.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <limits.h>
#include <wincon.h>
void
GetVersionEx(&ver);
} else {
}
}
/* If this returns NULL then an exception is pending */
}
}
/* Returns the working directory for the given drive, or NULL */
// verify drive is valid as _wgetdcwd in the VC++ 2010 runtime
// library does not handle invalid drives.
return NULL;
} else {
}
}
/* We cache the length of current working dir here to avoid
calling _wgetcwd() every time we need to resolve a relative
path. This piece of code needs to be revisited if chdir
makes its way into java runtime.
*/
int
//drive-relative
int dirlen = 0;
int di = 0;
else return 0; /* invalid drive name. */
}
return dirlen;
} else {
//relative to both drive and directory
if (curDirLenCached == -1) {
}
}
return curDirLenCached;
}
}
/*
The "abpathlen" is the size of the buffer needed by _wfullpath. If the
"path" is a relative path, it is "the length of the current dir" + "the
length of the path", if it's "absolute" already, it's the same as
pathlen which is the length of "path".
*/
if (abpath) {
/* Collapse instances of "foo\.." and ensure absoluteness before
going down to prefixing.
*/
} else {
/* _wfullpath fails if the pathlength exceeds 32k wchar.
Instead of doing more fancy things we simply copy the
ps into the return buffer, the subsequent win32 API will
probably fail with FileNotFoundException, which is expected
*/
if (pathbuf != 0) {
}
}
}
return pathbuf;
}
/* If this returns NULL then an exception is pending */
int pathlen = 0;
if (pathlen != 0) {
if (pathlen > 2 &&
{
} else {
if (pathbuf != 0) {
}
}
} else {
/* If the path came in as a relative path, need to verify if
its absolute form is bigger than max_path or not, if yes
need to (1)convert it to absolute and (2)prefix. This is
for "drive & directory" relative path is cached, so we only
calculate it once but for "drive-relative path we call
_wgetdcwd() and wcslen() everytime), but a hit we have
to take if we want to support relative path beyond max_path.
There is no way to predict how long the absolute path will be
(therefor allocate the sufficient memory block) before calling
_wfullpath(), we have to get the length of "current" dir first.
*/
} else {
if (pathbuf != 0) {
}
}
}
}
if (pathlen == 0) {
return NULL;
} else {
pathbuf[0] = L'\0';
}
}
if (pathbuf == 0) {
return NULL;
}
return pathbuf;
}
{
/* Note: O_TRUNC overrides O_CREAT */
(flags & O_TEMPORARY) ?
if (onNT) {
/* Exception already pending */
return -1;
}
h = CreateFileW(
pathbuf, /* Wide char path name */
sharing, /* File sharing flags */
NULL, /* Security attributes */
disposition, /* creation disposition */
flagsAndAttributes, /* flags and attributes */
NULL);
} else {
}
if (h == INVALID_HANDLE_VALUE) {
if (error == ERROR_TOO_MANY_OPEN_FILES) {
"Too many open files");
return -1;
}
return -1;
}
return (jlong) h;
}
void
{
if (h >= 0) {
}
}
/* These are functions that use a handle fd instead of the
old C style int fd as is used in HPI layer */
static int
handleNonSeekAvailable(jlong, long *);
static int
handleStdinAvailable(jlong, long *);
int
type = GetFileType(h);
/* Handle is for keyboard or pipe */
int ret;
long lpbytes;
if (stdInHandle == h) {
} else {
}
return ret;
}
/* Handle is for regular file */
if (type == FILE_TYPE_DISK) {
if (current < 0) {
return FALSE;
}
if (GetFileSizeEx(h, &filesize) == 0) {
return FALSE;
}
return TRUE;
}
return FALSE;
}
static int
/* This is used for available on non-seekable devices
* (like both named and anonymous pipes, such as pipes
* connected to an exec'd process).
* Standard Input is a special case.
*
*/
return FALSE;
}
/* PeekNamedPipe fails when at EOF. In that case we
* simply make *pbytes = 0 which is consistent with the
* behavior we get on Solaris when an fd is at EOF.
* The only alternative is to raise and Exception,
* which isn't really warranted.
*/
if (GetLastError() != ERROR_BROKEN_PIPE) {
return FALSE;
}
*pbytes = 0;
}
return TRUE;
}
static int
DWORD i = 0; /* Loop index */
return FALSE;
}
/* Construct an array of input records in the console buffer */
if (error == 0) {
}
/* lpBuffer must fit into 64K or else PeekConsoleInput fails */
if (numEvents > MAX_INPUT_EVENTS) {
}
if (bufferSize == 0)
bufferSize = 1;
return FALSE;
}
if (error == 0) {
return FALSE;
}
/* Examine input records for the number of bytes available */
for(i=0; i<numEvents; i++) {
curLength++;
if (*keyPressed == '\r')
}
}
}
*pbytes = (long) actualLength;
return TRUE;
}
/*
* This is documented to succeed on read-only files, but Win32's
* FlushFileBuffers functions fails with "access denied" in such a
* case. So we only signal an error if the error is *not* "access
* denied".
*/
JNIEXPORT int
/*
* From the documentation:
*
* On Windows NT, the function FlushFileBuffers fails if hFile
* is a handle to console output. That is because console
* output is not buffered. The function returns FALSE, and
* GetLastError returns ERROR_INVALID_HANDLE.
*
* On the other hand, on Win95, it returns without error. I cannot
* assume that 0, 1, and 2 are console, because if someone closes
* System.out and then opens a file, they might get file descriptor
* 1. An error on *that* version of 1 should be reported, whereas
* an error on System.out (which was the original 1) should be
* ignored. So I use isatty() to ensure that such an error was due
* to this bogosity, and if it was, I ignore the error.
*/
if (!FlushFileBuffers(handle)) {
return -1;
}
}
return 0;
}
int
return -1;
}
return 0;
}
{
if (h == INVALID_HANDLE_VALUE) {
return -1;
}
buf, /* address to put data */
len, /* number of bytes to read */
&read, /* number of bytes read */
NULL); /* no overlapped struct */
if (result == 0) {
if (error == ERROR_BROKEN_PIPE) {
return 0; /* EOF */
}
return -1;
}
return read;
}
{
if (h != INVALID_HANDLE_VALUE) {
} else {
}
buf, /* pointers to the buffers */
len, /* number of bytes to write */
&written, /* receives number of bytes written */
lpOv); /* overlapped struct */
}
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) {
return -1;
}
}
}
}
{
if (h == INVALID_HANDLE_VALUE) {
return 0;
}
/* Set the fd to -1 before closing it so that the timing window
* of other threads using the wrong fd (closed but recycled fd,
* that gets re-opened with some other filename) is reduced.
* Practically the chance of its occurance is low, however, we are
* taking extra precaution over here.
*/
if (CloseHandle(h) == 0) { /* Returns zero on failure */
}
return 0;
}
{
long highPos = 0;
}
op = FILE_CURRENT;
}
op = FILE_BEGIN;
}
return -1;
}
}