]> git.cworth.org Git - ttt/blobdiff - src/x.c
2005-11-08 Carl Worth <cworth@cworth.org>
[ttt] / src / x.c
diff --git a/src/x.c b/src/x.c
index 4062294d1f37e043b40e427fe70a73d694b8ac61..1695374c8c72a3c6423a69b69d15728c575055ee 100644 (file)
--- 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;
+}