X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fx.c;h=c35f4c88955f3147271d86c1c3113140aeafb496;hp=a95fedfbc5e8a142606698cf4ab629368e1e2e8d;hb=95898262b4ce4a2a3d36f70a4e6cc8188decc142;hpb=2b99e82a84be5e2f626b4a43eb7fd82254a7ea87 diff --git a/src/x.c b/src/x.c index a95fedf..c35f4c8 100644 --- a/src/x.c +++ b/src/x.c @@ -117,6 +117,22 @@ xrealloc (void *ptr, size_t size) return ret; } +FILE * +xfopen (const char *path, const char *mode) +{ + FILE *ret; + + ret = fopen (path, mode); + + if (ret == NULL) { + fprintf (stderr, "Error: fopen of %s failed: %s. Aborting.\n", + path, strerror (errno)); + exit (1); + } + + return ret; +} + FILE * xfdopen (int filedes, const char *mode) { @@ -134,14 +150,14 @@ xfdopen (int filedes, const char *mode) } void -xfreopen (const char *path, const char *mode, FILE *stream) +xdup2 (int oldfd, int newfd) { - FILE *ret; + int ret; - ret = freopen (path, mode, stream); - if (ret == NULL) { - fprintf (stderr, "Error: freopen of %s failed: %s. Aborting.\n", - path, strerror (errno)); + ret = dup2 (oldfd, newfd); + if (ret == -1) { + printf ("Error: dup2 failed: %s. Aborting.\n", + strerror (errno)); exit (1); } }