X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fx.c;h=dc5c1dd38e807ee300f9a1d77cc1ef187ef79f7d;hp=54566423e03f29c45c0d65f190e448a2ae18c79b;hb=84db9bf52aa25c19f7d547ea2dbec69ca4452300;hpb=c23865689e087ec70e36e13075f997ba39fcda75 diff --git a/src/x.c b/src/x.c index 5456642..dc5c1dd 100644 --- a/src/x.c +++ b/src/x.c @@ -133,7 +133,7 @@ xfdopen (int filedes, const char *mode) return ret; } -FILE * +void xfreopen (const char *path, const char *mode, FILE *stream) { FILE *ret; @@ -144,8 +144,6 @@ xfreopen (const char *path, const char *mode, FILE *stream) path, strerror (errno)); exit (1); } - - return ret; } char * @@ -153,6 +151,9 @@ xstrdup (const char *s) { char *ret; + if (s == NULL) + return NULL; + ret = strdup (s); if (ret == NULL) { @@ -250,3 +251,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; +}