---
hurd/fd-write.c | 49 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 41 insertions(+), 8 deletions(-)
diff --git a/hurd/fd-write.c b/hurd/fd-write.c
index 2dc2eedf..e3434130 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,52 @@ _hurd_fd_write (struct hurd_fd *fd,
{
error_t err;
vm_size_t wrote;
+ size_t wbytes = *nbytes;
+ 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 > UINT32_MAX ? UINT32_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;
+ }
- err = HURD_FD_PORT_USE_CANCEL (fd, _hurd_ctty_output (port, ctty, writefd));
- if (err)
- return err;
+
+ if (__glibc_unlikely (wrote > *nbytes)) /* Sanity check for bogus
server. */
+ return EGRATUITOUS;
+
+
+ tbytes += wrote;
+ wbytes -= wrote;
+ buf = (const char*) buf + wrote;
+
+ if (offset != -1)
+ offset += wrote;
+
+ if (wrote < *nbytes)
+ break;
+
+ }
+ while (wbytes != 0);
- if (__glibc_unlikely (wrote > *nbytes)) /* Sanity check for bogus
server. */
- return EGRATUITOUS;
- *nbytes = wrote;
+ *nbytes = tbytes;
return 0;
}
--
2.47.3