7 /* write buffer or bust
9 /* #include <iostuff.h>
11 /* ssize_t write_buf(fd, buf, len, timeout)
17 /* write_buf() writes a buffer to the named stream in as many
18 /* fragments as needed, and returns the number of bytes written,
19 /* which is always the number requested or an error indication.
23 /* File descriptor in the range 0..FD_SETSIZE.
25 /* Address of data to be written.
27 /* Amount of data to be written.
29 /* Bounds the time in seconds to wait until \fIfd\fD becomes writable.
30 /* A value <= 0 means do not wait; this is useful only when \fIfd\fR
33 /* write_buf() returns -1 in case of trouble. The global \fIerrno\fR
34 /* variable reflects the nature of the problem.
38 /* The Secure Mailer license must be distributed with this software.
41 /* IBM T.J. Watson Research
43 /* Yorktown Heights, NY 10598, USA
53 /* Utility library. */
58 /* write_buf - write buffer or bust */
60 ssize_t
write_buf(int fd
, const char *buf
, ssize_t len
, int timeout
)
62 const char *start
= buf
;
65 int time_left
= timeout
;
68 expire
= time((time_t *) 0) + time_left
;
71 if (time_left
> 0 && write_wait(fd
, time_left
) < 0)
73 if ((count
= write(fd
, buf
, len
)) < 0) {
74 if ((errno
== EAGAIN
&& time_left
> 0) || errno
== EINTR
)
82 if (len
> 0 && time_left
> 0) {
83 time_left
= expire
- time((time_t *) 0);