Mercurial > hg > toybox
comparison lib/lib.c @ 883:aca8323e2690
Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it.
author | Rob Landley <rob@landley.net> |
---|---|
date | Fri, 26 Apr 2013 02:41:05 -0500 |
parents | aa5bd0a358dd |
children | beb32d780164 |
comparison
equal
deleted
inserted
replaced
882:ae7a0fd5363f | 883:aca8323e2690 |
---|---|
737 return buf; | 737 return buf; |
738 } | 738 } |
739 | 739 |
740 */ | 740 */ |
741 | 741 |
742 | |
743 // Sleep for this many thousandths of a second | |
744 void msleep(long miliseconds) | |
745 { | |
746 struct timespec ts; | |
747 | |
748 ts.tv_sec = miliseconds/1000; | |
749 ts.tv_nsec = (miliseconds%1000)*1000000; | |
750 nanosleep(&ts, &ts); | |
751 } | |
752 | |
753 int xioctl(int fd, int request, void *data) | |
754 { | |
755 int rc; | |
756 | |
757 errno = 0; | |
758 rc = ioctl(fd, request, data); | |
759 if (rc == -1 && errno) perror_exit("ioctl %d", request); | |
760 | |
761 return rc; | |
762 } | |
763 | |
742 // Open a /var/run/NAME.pid file, dying if we can't write it or if it currently | 764 // Open a /var/run/NAME.pid file, dying if we can't write it or if it currently |
743 // exists and is this executable. | 765 // exists and is this executable. |
744 void xpidfile(char *name) | 766 void xpidfile(char *name) |
745 { | 767 { |
746 char pidfile[256], spid[32]; | 768 char pidfile[256], spid[32]; |