]> git.cworth.org Git - ttt/blobdiff - src/x.c
2005-11-14 Carl Worth <cworth@cworth.org>
[ttt] / src / x.c
diff --git a/src/x.c b/src/x.c
index 1695374c8c72a3c6423a69b69d15728c575055ee..8da355e3e015b0c390cb0869e53a96d1e2bb01e1 100644 (file)
--- a/src/x.c
+++ b/src/x.c
@@ -19,9 +19,7 @@
  * Author: Carl Worth <carl@theworths.org>
  */
 
-#include "ttt.h"
-
-#include <stdarg.h>
+#include "x.h"
 
 void
 xasprintf (char **strp, const char *fmt, ...)
@@ -127,13 +125,27 @@ xfdopen (int filedes, const char *mode)
     ret = fdopen (filedes, mode);
 
     if (ret == NULL) {
-       fprintf (stderr, "Error: fdopen failed: %s. Aborting.\n", strerror (errno));
+       fprintf (stderr, "Error: fdopen failed: %s. Aborting.\n",
+                strerror (errno));
        exit (1);
     }
 
     return ret;
 }
 
+void
+xfreopen (const char *path, const char *mode, FILE *stream)
+{
+    FILE *ret;
+
+    ret = freopen (path, mode, stream);
+    if (ret == NULL) {
+       fprintf (stderr, "Error: freopen of %s failed: %s. Aborting.\n",
+                path, strerror (errno));
+       exit (1);
+    }
+}
+
 char *
 xstrdup (const char *s)
 {
@@ -236,3 +248,33 @@ xselect (int                n,
 
     return ret;
 }
+
+ssize_t
+xread (int fd, void *buf, size_t count)
+{
+    int ret;
+
+    ret = read (fd, buf, count);
+    if (ret == -1) {
+       fprintf (stderr, "Error: read failed: %s. Aborting.\n",
+                strerror (errno));
+       exit (1);
+    }
+
+    return ret;
+}
+
+ssize_t
+xwrite (int fd, const void *buf, size_t count)
+{
+    int ret;
+
+    ret = write (fd, buf, count);
+    if (ret == -1) {
+       fprintf (stderr, "Error: write failed: %s. Aborting.\n",
+                strerror (errno));
+       exit (1);
+    }
+
+    return ret;
+}