Commit 1d189890 by Tom Tromey Committed by Tom Tromey

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
parent e36bf33a
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> 1999-09-02 Tom Tromey <tromey@cygnus.com>
* include/java-array.h (jobjectArrayjchar): Removed unused * include/java-array.h (jobjectArrayjchar): Removed unused
......
...@@ -302,7 +302,7 @@ if test -n "${with_cross_host}"; then ...@@ -302,7 +302,7 @@ if test -n "${with_cross_host}"; then
GCJ= GCJ=
fi fi
else 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(ctime_r ctime, break)
AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r) AC_CHECK_FUNCS(gmtime_r localtime_r readdir_r getpwuid_r)
AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath) AC_CHECK_FUNCS(access stat mkdir rename rmdir unlink realpath)
......
...@@ -137,6 +137,9 @@ ...@@ -137,6 +137,9 @@
/* Define if you have the ctime_r function. */ /* Define if you have the ctime_r function. */
#undef HAVE_CTIME_R #undef HAVE_CTIME_R
/* Define if you have the fstat function. */
#undef HAVE_FSTAT
/* Define if you have the fsync function. */ /* Define if you have the fsync function. */
#undef HAVE_FSYNC #undef HAVE_FSYNC
......
...@@ -234,17 +234,58 @@ java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count) ...@@ -234,17 +234,58 @@ java::io::FileDescriptor::read (jbyteArray buffer, jint offset, jint count)
jint jint
java::io::FileDescriptor::available (void) 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) #if defined (FIONREAD)
long num; r = ::ioctl (fd, FIONREAD, &num);
int r = ::ioctl (fd, FIONREAD, &num); if (r == -1 && errno == ENOTTY)
if (r == -1) {
JvThrow (new IOException (JvNewStringLatin1 (strerror (errno)))); // If the ioctl doesn't work, we don't care.
return (jint) num; r = 0;
num = 0;
}
else
num_set = true;
#elif defined (HAVE_SELECT) #elif defined (HAVE_SELECT)
int r = -1;
if (fd < 0) if (fd < 0)
errno = EBADF; {
else 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_set rd;
FD_ZERO (&rd); FD_ZERO (&rd);
...@@ -253,10 +294,13 @@ java::io::FileDescriptor::available (void) ...@@ -253,10 +294,13 @@ java::io::FileDescriptor::available (void)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
r = ::select (fd + 1, &rd, NULL, NULL, &tv); r = ::select (fd + 1, &rd, NULL, NULL, &tv);
if (r == -1)
goto posix_error;
num = r == 0 ? 0 : 1;
} }
if (r == -1) #endif /* HAVE_SELECT */
JvThrow (new IOException (JvNewStringLatin1 (strerror (errno))));
return r == 0 ? 0 : 1; return (jint) num;
#else #else
JvThrow (new IOException (JvNewStringLatin1 ("unimplemented"))); JvThrow (new IOException (JvNewStringLatin1 ("unimplemented")));
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment