diff options
author | Rob Landley <rob@landley.net> | 2013-08-07 12:19:51 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2013-08-07 12:19:51 -0500 |
commit | 1aa75118c46c8fbe0eeead18974d25e5f13274d5 (patch) | |
tree | 643b500aa234d17a8fc5cf1dad8d61e6fbb5aeae /lib | |
parent | 17ea5644d93ff1ced28d3602ac244cb6022f3ba6 (diff) | |
download | toybox-1aa75118c46c8fbe0eeead18974d25e5f13274d5.tar.gz |
Forgot to check in xfdopen(). My bad.
Failure of fdopen() is most likely failure of malloc() for the FILE structure.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.h | 1 | ||||
-rw-r--r-- | lib/xwrap.c | 9 |
2 files changed, 10 insertions, 0 deletions
@@ -106,6 +106,7 @@ int xcreate(char *path, int flags, int mode); 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); diff --git a/lib/xwrap.c b/lib/xwrap.c index adf3e752..9f1dc996 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -172,6 +172,15 @@ int xdup(int fd) 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) { |