Re: [kaffe] InputStream#available() for System.in throws IOException

2005-08-30 Thread Ito Kazumitsu
From: Ito Kazumitsu <[EMAIL PROTECTED]>
Subject: Re: [kaffe] InputStream#available() for System.in throws IOException
Date: Tue, 30 Aug 2005 13:57:07 +0900 (JST)

> So here is my proposed patch.

I am checking this in.

___
kaffe mailing list
kaffe@kaffe.org
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe


Re: [kaffe] InputStream#available() for System.in throws IOException

2005-08-29 Thread Ito Kazumitsu
From: Ito Kazumitsu <[EMAIL PROTECTED]>
Subject: [kaffe] InputStream#available() for System.in throws IOException
Date: Tue, 30 Aug 2005 01:54:52 +0900 (JST)

> Case 1: Terminal input
> $ kaffe TestBufferedReader
> 
> java.io.IOException: No such file or directory

> Case 2: Pipe
> $ echo  | kaffe TestBufferedReader 
> java.io.IOException: No such file or directory

> Case 3: File input - OK
> $ kaffe TestBufferedReader  Case 4: Here document - OK
> $ kaffe TestBufferedReader < > 
> > EOF

The message text of the IOException is meaningless.
This IOException comes from the macro TARGET_NATIVE_FILE_AVAILABLE
defined in libraries/clib/target/Linux/target_native_file.h.

If the standard input is piped to another process or it is a
character device, KFSTAT(filedescriptor,&__statBuffer) returns 0
but S_ISREG(__statBuffer.st_mode) is false because it is not a
regular file.

The solution may be either

  (a) if S_ISREG(__statBuffer.st_mode) is false, try other
  methods as libraries/clib/nio/FileChannelImpl.c did before.

or

  (b) if S_ISREG(__statBuffer.st_mode) is false, give up trying
  to figure out available length and just return 0.

I think (b) is simple and reasonable enough. Running the following
program on Sun's JDK,

public class TestAvailable {
public static void main(String[] args) throws Exception {
System.out.println(System.in.available());
}
}

I find Sun's System.in.available() often returns 0 if the standerd
input is a terminal or is piped to another process.

So here is my proposed patch.

--- libraries/clib/target/Linux/target_native_file.h.orig   Fri Aug  5 
10:20:19 2005
+++ libraries/clib/target/Linux/target_native_file.hTue Aug 30 13:31:24 2005
@@ -138,18 +138,26 @@
 \
 length=0; \
 \
-if ((KFSTAT(filedescriptor,&__statBuffer)==0) && 
S_ISREG(__statBuffer.st_mode)) \
+if (KFSTAT(filedescriptor,&__statBuffer)==0) \
 { \
- int klseek_result; \
-  klseek_result=(KLSEEK(filedescriptor,0,SEEK_CUR, &__n)); \
-  if (klseek_result == 0) \
+  if (S_ISREG(__statBuffer.st_mode)) \
   { \
-
length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size-__n); \
-result=TARGET_NATIVE_OK; \
+int klseek_result; \
+klseek_result=(KLSEEK(filedescriptor,0,SEEK_CUR, &__n));   \
+if (klseek_result == 0) \
+{ \
+  
length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(__statBuffer.st_size-__n); \
+  result=TARGET_NATIVE_OK; \
+} \
+else \
+{ \
+  result=TARGET_NATIVE_ERROR; \
+} \
   } \
   else \
   { \
-result=TARGET_NATIVE_ERROR; \
+  length=TARGET_NATIVE_MATH_INT_INT32_TO_INT64(0); \
+  result=TARGET_NATIVE_OK; \
   } \
 } \
 else \

___
kaffe mailing list
kaffe@kaffe.org
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe


[kaffe] InputStream#available() for System.in throws IOException

2005-08-29 Thread Ito Kazumitsu
Hi,

The program attached below throws java.io.IOException when run with
current CVS version of Kaffe.

Case 1: Terminal input
$ kaffe TestBufferedReader

java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   at java.io.FilterInputStream.available (FilterInputStream.java:129)
   at java.io.BufferedInputStream.read (BufferedInputStream.java:276)
   at java.io.FilterInputStream.read (FilterInputStream.java:173)
   at java.io.InputStreamReader.read (InputStreamReader.java:395)
   at java.io.BufferedReader.fill (BufferedReader.java:373)
   at java.io.BufferedReader.readLine (BufferedReader.java:475)
   at TestBufferedReader.main (TestBufferedReader.java:12)
java.io.IOException: No such file or directory

Case 2: Pipe
$ echo  | kaffe TestBufferedReader 
java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   at java.io.FilterInputStream.available (FilterInputStream.java:129)
   at java.io.BufferedInputStream.read (BufferedInputStream.java:276)
   at java.io.FilterInputStream.read (FilterInputStream.java:173)
   at java.io.InputStreamReader.read (InputStreamReader.java:395)
   at java.io.BufferedReader.fill (BufferedReader.java:373)
   at java.io.BufferedReader.readLine (BufferedReader.java:475)
   at TestBufferedReader.main (TestBufferedReader.java:12)
java.io.IOException: No such file or directory

Case 3: File input - OK
$ kaffe TestBufferedReader  
> EOF
$

This error occurs on both FreeBSD and Linux.
Slight differences among operating systems are:

(1) On Linux 2.6.7-co-0.6.2, the message of the IOException is
"Success" instead of "No such file or directory".

(2) On Linux 2.4.18-3, instead of throwing IOException, the program
seems to go into a deadlock. But giving an argument to the
program, we see the same IOException.

$ echo  | kaffe TestBufferedReader US-ASCII
java.io.IOException: No such file or directory
   at gnu.java.nio.channels.FileChannelImpl.available (FileChannelImpl.java)
   at java.io.FileInputStream.available (FileInputStream.java:165)
   ...

And here is the program for testing.
import java.io.*;

public class TestBufferedReader {

public static void main(String[] args) throws Exception {
  try {
BufferedReader rdr = new BufferedReader(
(args.length > 0 ?
  new InputStreamReader(System.in, args[0]) :
  new InputStreamReader(System.in)));
while (true) {
String s = rdr.readLine();
if (s == null) break;
}
  }
  catch (Exception e) {
e.printStackTrace();
throw e;
  }
}
}

___
kaffe mailing list
kaffe@kaffe.org
http://kaffe.org/cgi-bin/mailman/listinfo/kaffe