diff options
Diffstat (limited to 'common/iobuf.c')
-rw-r--r-- | common/iobuf.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/common/iobuf.c b/common/iobuf.c index 4ec151f5f..04b17ff17 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -1260,6 +1260,32 @@ iobuf_is_pipe_filename (const char *fname) return check_special_filename (fname) != -1; } + +/* Either open the file specified by the file descriptor FD or - if FD + is -1, the file with name FNAME. As of now MODE is assumed to be + "rb" if FNAME is used. In contrast to iobuf_fdopen the file + descriptor FD will not be closed during an iobuf_close. */ +iobuf_t +iobuf_open_fd_or_name (gnupg_fd_t fd, const char *fname, const char *mode) +{ + iobuf_t a; + + if (fd == -1) + a = iobuf_open (fname); + else + { + int fd2; + + fd2 = dup (fd); + if (fd2 == -1) + a = NULL; + else + a = iobuf_fdopen (fd2, mode); + } + return a; +} + + /**************** * Create a head iobuf for reading from a file * returns: NULL if an error occures and sets errno |