X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fx.c;h=1695374c8c72a3c6423a69b69d15728c575055ee;hp=4062294d1f37e043b40e427fe70a73d694b8ac61;hb=2cd70db8433cc9d02a4ca784190260889c835198;hpb=80c3009d01077a141a0803267a1f0aff217ed61c diff --git a/src/x.c b/src/x.c index 4062294..1695374 100644 --- a/src/x.c +++ b/src/x.c @@ -161,3 +161,78 @@ xfwrite (const void *ptr, size_t size, size_t nmemb, FILE *stream) exit (1); } } + +int +xsocket (int domain, int type, int protocol) +{ + int ret; + + ret = socket (domain, type, protocol); + if (ret == -1) { + fprintf (stderr, "Error: socket failed: %s. Aborting.\n", + strerror (errno)); + exit (1); + } + + return ret; +} + +void +xbind (int sockfd, const struct sockaddr *my_addr, socklen_t addrlen) +{ + int ret; + + ret = bind (sockfd, my_addr, addrlen); + if (ret == -1) { + fprintf (stderr, "Error: bind failed: %s. Aborting.\n", + strerror (errno)); + exit (1); + } +} + +void +xlisten (int s, int backlog) +{ + int ret; + + ret = listen (s, backlog); + if (ret == -1) { + fprintf (stderr, "Error: listen failed: %s. Aborting.\n", + strerror (errno)); + exit (1); + } +} + +int +xfcntl (int fd, int cmd, long arg) +{ + int ret; + + ret = fcntl (fd, cmd, arg); + if (ret == -1) { + fprintf (stderr, "Error: fcntl failed: %s. Aborting.\n", + strerror (errno)); + exit (1); + } + + return ret; +} + +int +xselect (int n, + fd_set *readfds, + fd_set *writefds, + fd_set *exceptfds, + struct timeval *timeout) +{ + int ret; + + ret = select (n, readfds, writefds, exceptfds, timeout); + if (ret == -1) { + fprintf (stderr, "Error: select failed: %s. Aborting.\n", + strerror (errno)); + exit (1); + } + + return ret; +}