# HG changeset patch # User Rob Landley # Date 1366962065 18000 # Node ID aca8323e269036b9ca7ed940671e7e78d3798e47 # Parent ae7a0fd5363f42e8dab96a36cc8a7903b95a68e7 Add posix headers to toynet.h, move xioctl() to lib.c, introduce lib/net.c and move xsocket() to it. diff -r ae7a0fd5363f -r aca8323e2690 lib/lib.c --- a/lib/lib.c Fri Apr 26 01:59:13 2013 -0500 +++ b/lib/lib.c Fri Apr 26 02:41:05 2013 -0500 @@ -739,6 +739,28 @@ */ + +// Sleep for this many thousandths of a second +void msleep(long miliseconds) +{ + struct timespec ts; + + ts.tv_sec = miliseconds/1000; + ts.tv_nsec = (miliseconds%1000)*1000000; + nanosleep(&ts, &ts); +} + +int xioctl(int fd, int request, void *data) +{ + int rc; + + errno = 0; + rc = ioctl(fd, request, data); + if (rc == -1 && errno) perror_exit("ioctl %d", request); + + return rc; +} + // Open a /var/run/NAME.pid file, dying if we can't write it or if it currently // exists and is this executable. void xpidfile(char *name) diff -r ae7a0fd5363f -r aca8323e2690 lib/lib.h --- a/lib/lib.h Fri Apr 26 01:59:13 2013 -0500 +++ b/lib/lib.h Fri Apr 26 02:41:05 2013 -0500 @@ -119,6 +119,8 @@ off_t lskip(int fd, off_t offset); char *readfile(char *name); char *xreadfile(char *name); +void msleep(long miliseconds); +int xioctl(int fd, int request, void *data); char *xgetcwd(void); void xstat(char *path, struct stat *st); char *xabspath(char *path, int exact); @@ -152,6 +154,9 @@ void for_each_pid_with_name_in(char **names, int (*callback)(pid_t pid, char *name)); unsigned long xstrtoul(const char *nptr, char **endptr, int base); +// net.c +int xsocket(int domain, int type, int protocol); + // getmountlist.c struct mtab_list { struct mtab_list *next; diff -r ae7a0fd5363f -r aca8323e2690 lib/net.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/net.c Fri Apr 26 02:41:05 2013 -0500 @@ -0,0 +1,10 @@ +#include "toys.h" +#include "toynet.h" + +int xsocket(int domain, int type, int protocol) +{ + int fd = socket(domain, type, protocol); + + if (fd < 0) perror_exit("socket %x %x", type, protocol); + return fd; +} diff -r ae7a0fd5363f -r aca8323e2690 toynet.h --- a/toynet.h Fri Apr 26 01:59:13 2013 -0500 +++ b/toynet.h Fri Apr 26 02:41:05 2013 -0500 @@ -2,9 +2,12 @@ // don't include network support, so we shouldn't include it unless we're // going to build it. +#include +#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include + diff -r ae7a0fd5363f -r aca8323e2690 toys/pending/ifconfig.c --- a/toys/pending/ifconfig.c Fri Apr 26 01:59:13 2013 -0500 +++ b/toys/pending/ifconfig.c Fri Apr 26 02:41:05 2013 -0500 @@ -32,7 +32,6 @@ #include "toys.h" #include "toynet.h" -#include #include #include @@ -61,9 +60,6 @@ unsigned long long val[16]; }; -#define HW_NAME_LEN 20 -#define HW_TITLE_LEN 30 - #define IO_MAP_INDEX 0x100 //from kernel header ipv6.h @@ -96,19 +92,6 @@ # define INFINIBAND_ALEN 20 #endif -void xioctl(int fd, int request, void *data) -{ - if (ioctl(fd, request, data) < 0) perror_exit("ioctl %d", request); -} - -int xsocket(int domain, int type, int protocol) -{ - int fd = socket(domain, type, protocol); - - if (fd < 0) perror_exit("socket %x %x", type, protocol); - return fd; -} - /* * verify the host is local unix path. * if so, set the swl input param accordingly.