4614 } else {
4615 ret = nonSeekAvailable(fd, &lpbytes);
4616 }
4617 (*bytes) = (jlong)(lpbytes);
4618 return ret;
4619 }
4620 if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) {
4621 return FALSE;
4622 } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) {
4623 return FALSE;
4624 } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) {
4625 return FALSE;
4626 }
4627 *bytes = end - cur;
4628 return TRUE;
4629 } else {
4630 return FALSE;
4631 }
4632 }
4633
4634 // This code is a copy of JDK's nonSeekAvailable
4635 // from src/windows/hpi/src/sys_api_md.c
4636
4637 static int nonSeekAvailable(int fd, long *pbytes) {
4638 // This is used for available on non-seekable devices
4639 // (like both named and anonymous pipes, such as pipes
4640 // connected to an exec'd process).
4641 // Standard Input is a special case.
4642 HANDLE han;
4643
4644 if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) {
4645 return FALSE;
4646 }
4647
4648 if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) {
4649 // PeekNamedPipe fails when at EOF. In that case we
4650 // simply make *pbytes = 0 which is consistent with the
4651 // behavior we get on Solaris when an fd is at EOF.
4652 // The only alternative is to raise an Exception,
4653 // which isn't really warranted.
|
4614 } else {
4615 ret = nonSeekAvailable(fd, &lpbytes);
4616 }
4617 (*bytes) = (jlong)(lpbytes);
4618 return ret;
4619 }
4620 if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) {
4621 return FALSE;
4622 } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) {
4623 return FALSE;
4624 } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) {
4625 return FALSE;
4626 }
4627 *bytes = end - cur;
4628 return TRUE;
4629 } else {
4630 return FALSE;
4631 }
4632 }
4633
4634 void os::flockfile(FILE* fp) {
4635 _lock_file(fp);
4636 }
4637
4638 void os::funlockfile(FILE* fp) {
4639 _unlock_file(fp);
4640 }
4641
4642 // This code is a copy of JDK's nonSeekAvailable
4643 // from src/windows/hpi/src/sys_api_md.c
4644
4645 static int nonSeekAvailable(int fd, long *pbytes) {
4646 // This is used for available on non-seekable devices
4647 // (like both named and anonymous pipes, such as pipes
4648 // connected to an exec'd process).
4649 // Standard Input is a special case.
4650 HANDLE han;
4651
4652 if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) {
4653 return FALSE;
4654 }
4655
4656 if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) {
4657 // PeekNamedPipe fails when at EOF. In that case we
4658 // simply make *pbytes = 0 which is consistent with the
4659 // behavior we get on Solaris when an fd is at EOF.
4660 // The only alternative is to raise an Exception,
4661 // which isn't really warranted.
|