changeset 991:252caf3d2b88

Forgot to check in xfdopen(). My bad. Failure of fdopen() is most likely failure of malloc() for the FILE structure.
author Rob Landley <rob@landley.net>
date Wed, 07 Aug 2013 12:19:51 -0500
parents 8caeba551a28
children 910f35ff76be
files lib/lib.h lib/xwrap.c
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.h	Wed Aug 07 11:51:26 2013 -0500
+++ b/lib/lib.h	Wed Aug 07 12:19:51 2013 -0500
@@ -106,6 +106,7 @@
 int xopen(char *path, int flags);
 void xclose(int fd);
 int xdup(int fd);
+FILE *xfdopen(int fd, char *mode);
 FILE *xfopen(char *path, char *mode);
 size_t xread(int fd, void *buf, size_t len);
 void xreadall(int fd, void *buf, size_t len);
--- a/lib/xwrap.c	Wed Aug 07 11:51:26 2013 -0500
+++ b/lib/xwrap.c	Wed Aug 07 12:19:51 2013 -0500
@@ -172,6 +172,15 @@
   return fd;
 }
 
+FILE *xfdopen(int fd, char *mode)
+{
+  FILE *f = fdopen(fd, mode);
+
+  if (!f) perror_exit("xfdopen");
+
+  return f;
+}
+
 // Die unless we can open/create a file, returning FILE *.
 FILE *xfopen(char *path, char *mode)
 {