X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fstring%2Fstring.c;h=6e473af36cf3862580e6c1f706d46861e99dc874;hp=7686813c9a392ab5cf94c8b624e3037e28fbd601;hb=be6b32cbe44df085efbae36c07b566bda88c6154;hpb=e52b97e4d99af6e2a564731c23c6c86e373aedaa;ds=sidebyside diff --git a/ccan/string/string.c b/ccan/string/string.c index 7686813c..6e473af3 100644 --- a/ccan/string/string.c +++ b/ccan/string/string.c @@ -10,6 +10,7 @@ #include #include #include +#include "noerr/noerr.h" char **strsplit(const void *ctx, const char *string, const char *delims, unsigned int *nump) @@ -67,3 +68,21 @@ void *grab_fd(const void *ctx, int fd) return buffer; } + +void *grab_file(const void *ctx, const char *filename) +{ + int fd; + char *buffer; + + if (streq(filename, "-")) + fd = dup(STDIN_FILENO); + else + fd = open(filename, O_RDONLY, 0); + + if (fd < 0) + return NULL; + + buffer = grab_fd(ctx, fd); + close_noerr(fd); + return buffer; +}