---
hurd/fd-write.c | 44 ++++++++++++++++++++++++++++++++++++--------
1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/hurd/fd-write.c b/hurd/fd-write.c
index 2dc2eedf..76ea1e43 100644
--- a/hurd/fd-write.c
+++ b/hurd/fd-write.c
@@ -18,6 +18,7 @@
#include <errno.h>
#include <unistd.h>
+#include <stdint.h>
#include <hurd.h>
#include <hurd/fd.h>
@@ -27,20 +28,47 @@ _hurd_fd_write (struct hurd_fd *fd,
{
error_t err;
vm_size_t wrote;
+ vm_size_t wbytes = *nbytes;
+ vm_size_t tbytes = 0;
error_t writefd (io_t port)
+ {
+ return __io_write (port, buf, *nbytes, offset, &wrote);
+ }
+
+ do
{
- return __io_write (port, buf, *nbytes, offset, &wrote);
- }
+ *nbytes = wbytes > INT32_MAX ? INT32_MAX : wbytes;
+
+ err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty,
writefd));
+ if (err)
+ {
+ if (tbytes > 0)
+ {
+ *nbytes = tbytes;
+ return 0;
+
+ }
+ return err;
+ }
+
+ if (__glibc_unlikely (wrote > *nbytes)) /* Sanity check for bogus
server. */
+ return EGRATUITOUS;
- err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty, writefd));
- if (err)
- return err;
+ wbytes -=wrote;
+ tbytes += wrote;
- if (__glibc_unlikely (wrote > *nbytes)) /* Sanity check for bogus
server. */
- return EGRATUITOUS;
+ buf = (const char*) buf + wrote;
- *nbytes = wrote;
+ if(offset != -1)
+ offset += wrote;
+
+ if(wrote < *nbytes)
+ break;
+
+ }
+ while(wbytes != 0);
+ *nbytes = tbytes;
return 0;
}
--
2.47.3