Commit 66c8aed2 by Tom Tromey Committed by Tom Tromey

natFileDescriptorPosix.cc (open): Allocate buffer to correct size.

	* java/io/natFileDescriptorPosix.cc (open): Allocate buffer to
	correct size.
	(write): Loop until write completes.  From Corey Minyard.

From-SVN: r42749
parent c9682caf
2001-05-31 Tom Tromey <tromey@redhat.com>
* java/io/natFileDescriptorPosix.cc (open): Allocate buffer to
correct size.
(write): Loop until write completes. From Corey Minyard.
2001-05-29 Laurent Guerby <guerby@acm.org> 2001-05-29 Laurent Guerby <guerby@acm.org>
* java/awt/geom/Rectangle2D.java: fix doc typo. * java/awt/geom/Rectangle2D.java: fix doc typo.
......
...@@ -68,10 +68,8 @@ java::io::FileDescriptor::sync (void) ...@@ -68,10 +68,8 @@ java::io::FileDescriptor::sync (void)
jint jint
java::io::FileDescriptor::open (jstring path, jint jflags) java::io::FileDescriptor::open (jstring path, jint jflags)
{ {
// FIXME: eww. char *buf = (char *) _Jv_AllocBytes (_Jv_GetStringUTFLength (path) + 1);
char buf[MAXPATHLEN];
jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf); jsize total = JvGetStringUTFRegion (path, 0, path->length(), buf);
// FIXME?
buf[total] = '\0'; buf[total] = '\0';
int flags = 0; int flags = 0;
#ifdef O_BINARY #ifdef O_BINARY
...@@ -121,7 +119,10 @@ void ...@@ -121,7 +119,10 @@ void
java::io::FileDescriptor::write (jint b) java::io::FileDescriptor::write (jint b)
{ {
jbyte d = (jbyte) b; jbyte d = (jbyte) b;
int r = ::write (fd, &d, 1); int r = 0;
while (r != 1)
{
r = ::write (fd, &d, 1);
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
InterruptedIOException *iioe InterruptedIOException *iioe
...@@ -131,7 +132,7 @@ java::io::FileDescriptor::write (jint b) ...@@ -131,7 +132,7 @@ java::io::FileDescriptor::write (jint b)
} }
else if (r == -1) else if (r == -1)
throw new IOException (JvNewStringLatin1 (strerror (errno))); throw new IOException (JvNewStringLatin1 (strerror (errno)));
// FIXME: loop if r != 1. }
} }
void void
...@@ -142,17 +143,26 @@ java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len) ...@@ -142,17 +143,26 @@ java::io::FileDescriptor::write (jbyteArray b, jint offset, jint len)
if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b)) if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
throw new java::lang::ArrayIndexOutOfBoundsException; throw new java::lang::ArrayIndexOutOfBoundsException;
jbyte *bytes = elements (b) + offset; jbyte *bytes = elements (b) + offset;
int written = 0;
while (len > 0)
{
int r = ::write (fd, bytes, len); int r = ::write (fd, bytes, len);
if (r != -1)
written += r;
if (java::lang::Thread::interrupted()) if (java::lang::Thread::interrupted())
{ {
InterruptedIOException *iioe InterruptedIOException *iioe
= new InterruptedIOException (JvNewStringLatin1 ("write interrupted")); = new InterruptedIOException (JvNewStringLatin1 ("write interrupted"));
iioe->bytesTransferred = r == -1 ? 0 : r; iioe->bytesTransferred = written;
throw iioe; throw iioe;
} }
else if (r == -1) else if (r == -1)
throw new IOException (JvNewStringLatin1 (strerror (errno))); throw new IOException (JvNewStringLatin1 (strerror (errno)));
// FIXME: loop if r != len.
len -= r;
bytes += r;
}
} }
void void
......
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