#include <stddef.h>
Include dependency graph for writen.h:
This graph shows which files directly or indirectly include this file:
Go to the source code of this file.
Functions | |
int | writen (int fd, const void *vptr, int n, double timeout) |
|
Definition at line 49 of file writen.c. 00050 { 00051 int nleft; 00052 long nwritten; 00053 char *ptr; 00054 double int_part; 00055 struct timeval timeout_tv; 00056 fd_set write_fd_set; 00057 00058 timeout_tv.tv_sec = (long) _timeout; 00059 timeout_tv.tv_usec = (long) (_timeout * 1000000.0); 00060 if (timeout_tv.tv_usec >= 1000000) 00061 { 00062 timeout_tv.tv_usec = timeout_tv.tv_usec % 1000000; 00063 } 00064 FD_ZERO (&write_fd_set); 00065 RCS_FD_SET (fd, &write_fd_set); 00066 00067 ptr = (char *) vptr; /* can't do pointer arithmetic on void* */ 00068 nleft = n; 00069 while (nleft > 0) 00070 { 00071 if (_timeout > 0.0) 00072 { 00073 switch (dl_select 00074 (fd + 1, (fd_set *) NULL, &write_fd_set, (fd_set *) NULL, 00075 &timeout_tv)) 00076 { 00077 case -1: 00078 rcs_print_error ("Error in select: %d -> %s\n", errno, 00079 strerror (errno)); 00080 return -1; 00081 00082 case 0: 00083 rcs_print_error ("Write timed out.\n"); 00084 return -1; 00085 00086 default: 00087 break; 00088 } 00089 } 00090 if ((nwritten = write (fd, ptr, nleft)) == -1) 00091 { 00092 rcs_print_error ("Write error: %d = %s", errno, strerror (errno)); 00093 return (-1); /* error */ 00094 } 00095 00096 nleft -= nwritten; 00097 ptr += nwritten; 00098 } 00099 return (n); 00100 } |