re GNATS libgcj/3 (FileInputStream.available always returns 0)

* configure: Rebuilt.
	* configure.in: Check for fstat function.
	* java/io/natFileDescriptorPosix.cc (available): Use fstat() if
	FIONREAD fails.
This fixes PR 3

From-SVN: r29078
This commit is contained in:
Tom Tromey 1999-09-03 07:42:40 +00:00 committed by Tom Tromey
parent e36bf33a3b
commit 1d189890ae
5 changed files with 301 additions and 236 deletions

View File

@ -1,3 +1,10 @@
1999-09-03 Tom Tromey <tromey@cygnus.com>
* configure: Rebuilt.
* configure.in: Check for fstat function.
* java/io/natFileDescriptorPosix.cc (available): Use fstat() if
FIONREAD fails.
1999-09-02 Tom Tromey <tromey@cygnus.com>
* include/java-array.h (jobjectArrayjchar): Removed unused

457
libjava/configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -302,7 +302,7 @@ if test -n "${with_cross_host}"; then
GCJ=
fi
else
AC_CHECK_FUNCS(strerror ioctl select open fsync sleep)
AC_CHECK_FUNCS(strerror ioctl select fstat open fsync sleep)
AC_CHECK_FUNCS(ctime_r ctime, break)
AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r)
AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath)

View File

@ -137,6 +137,9 @@
/* Define if you have the ctime_r function. */
#undef HAVE_CTIME_R
/* Define if you have the fstat function. */
#undef HAVE_FSTAT
/* Define if you have the fsync function. */
#undef HAVE_FSYNC

View File

@ -234,17 +234,58 @@ java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
jint
java::io::FileDescriptor::available (void)
{
#if defined (FIONREAD) || defined (HAVE_SELECT) || defined (HAVE_FSTAT)
long num = 0;
int r = 0;
bool num_set = false;
#if defined (FIONREAD)
long num;
int r = ::ioctl (fd, FIONREAD, &num);
if (r == -1)
JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
return (jint) num;
#elif defined (HAVE_SELECT)
int r = -1;
if (fd < 0)
errno = EBADF;
r = ::ioctl (fd, FIONREAD, &num);
if (r == -1 && errno == ENOTTY)
{
// If the ioctl doesn't work, we don't care.
r = 0;
num = 0;
}
else
num_set = true;
#elif defined (HAVE_SELECT)
if (fd < 0)
{
errno = EBADF;
r = -1;
}
#endif
if (r == -1)
{
posix_error:
JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
}
// If we didn't get anything, and we have fstat, then see if see if
// we're reading a regular file. On many systems, FIONREAD does not
// work on regular files; select() likewise returns a useless
// result. This is run incorrectly when FIONREAD does work on
// regular files and we are at the end of the file. However, this
// case probably isn't very important.
#if defined (HAVE_FSTAT)
if (! num_set)
{
struct stat sb;
off_t where;
if (fstat (fd, &sb) != -1
&& S_ISREG (sb.st_mode)
&& (where = lseek (fd, SEEK_CUR, 0)) != (off_t) -1)
{
num = (long) (sb.st_size - where);
num_set = true;
}
}
#endif /* HAVE_FSTAT */
#if defined (HAVE_SELECT)
if (! num_set)
{
fd_set rd;
FD_ZERO (&rd);
@ -253,10 +294,13 @@ java::io::FileDescriptor::available (void)
tv.tv_sec = 0;
tv.tv_usec = 0;
r = ::select (fd + 1, &rd, NULL, NULL, &tv);
if (r == -1)
goto posix_error;
num = r == 0 ? 0 : 1;
}
if (r == -1)
JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
return r == 0 ? 0 : 1;
#endif /* HAVE_SELECT */
return (jint) num;
#else
JvThrow (new IOException (JvNewStringLatin1 ("unimplemented")));
#endif