4648 } else {
4649 ret = nonSeekAvailable(fd, &lpbytes);
4650 }
4651 (*bytes) = (jlong)(lpbytes);
4652 return ret;
4653 }
4654 if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) {
4655 return FALSE;
4656 } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) {
4657 return FALSE;
4658 } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) {
4659 return FALSE;
4660 }
4661 *bytes = end - cur;
4662 return TRUE;
4663 } else {
4664 return FALSE;
4665 }
4666 }
4667
4668 // This code is a copy of JDK's nonSeekAvailable
4669 // from src/windows/hpi/src/sys_api_md.c
4670
4671 static int nonSeekAvailable(int fd, long *pbytes) {
4672 // This is used for available on non-seekable devices
4673 // (like both named and anonymous pipes, such as pipes
4674 // connected to an exec'd process).
4675 // Standard Input is a special case.
4676 HANDLE han;
4677
4678 if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) {
4679 return FALSE;
4680 }
4681
4682 if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) {
4683 // PeekNamedPipe fails when at EOF. In that case we
4684 // simply make *pbytes = 0 which is consistent with the
4685 // behavior we get on Solaris when an fd is at EOF.
4686 // The only alternative is to raise an Exception,
4687 // which isn't really warranted.
|
4648 } else {
4649 ret = nonSeekAvailable(fd, &lpbytes);
4650 }
4651 (*bytes) = (jlong)(lpbytes);
4652 return ret;
4653 }
4654 if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) {
4655 return FALSE;
4656 } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) {
4657 return FALSE;
4658 } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) {
4659 return FALSE;
4660 }
4661 *bytes = end - cur;
4662 return TRUE;
4663 } else {
4664 return FALSE;
4665 }
4666 }
4667
4668 void os::flockfile(FILE* fp) {
4669 _lock_file(fp);
4670 }
4671
4672 void os::funlockfile(FILE* fp) {
4673 _unlock_file(fp);
4674 }
4675
4676 // This code is a copy of JDK's nonSeekAvailable
4677 // from src/windows/hpi/src/sys_api_md.c
4678
4679 static int nonSeekAvailable(int fd, long *pbytes) {
4680 // This is used for available on non-seekable devices
4681 // (like both named and anonymous pipes, such as pipes
4682 // connected to an exec'd process).
4683 // Standard Input is a special case.
4684 HANDLE han;
4685
4686 if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) {
4687 return FALSE;
4688 }
4689
4690 if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) {
4691 // PeekNamedPipe fails when at EOF. In that case we
4692 // simply make *pbytes = 0 which is consistent with the
4693 // behavior we get on Solaris when an fd is at EOF.
4694 // The only alternative is to raise an Exception,
4695 // which isn't really warranted.
|