summaryrefslogtreecommitdiffstats
path: root/timeoutwrite.c
diff options
context:
space:
mode:
Diffstat (limited to 'timeoutwrite.c')
-rw-r--r--timeoutwrite.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/timeoutwrite.c b/timeoutwrite.c
new file mode 100644
index 0000000..516d283
--- /dev/null
+++ b/timeoutwrite.c
@@ -0,0 +1,22 @@
1#include "timeoutwrite.h"
2#include "select.h"
3#include "error.h"
4#include "readwrite.h"
5
6int timeoutwrite(t,fd,buf,len) int t; int fd; char *buf; int len;
7{
8 fd_set wfds;
9 struct timeval tv;
10
11 tv.tv_sec = t;
12 tv.tv_usec = 0;
13
14 FD_ZERO(&wfds);
15 FD_SET(fd,&wfds);
16
17 if (select(fd + 1,(fd_set *) 0,&wfds,(fd_set *) 0,&tv) == -1) return -1;
18 if (FD_ISSET(fd,&wfds)) return write(fd,buf,len);
19
20 errno = error_timeout;
21 return -1;
22}