aboutsummaryrefslogtreecommitdiffstats
path: root/util/iobuf.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>1999-01-13 13:12:50 +0000
committerWerner Koch <[email protected]>1999-01-13 13:12:50 +0000
commite99e43cd531c4ba26bb1b2fbc0e356f95126ae24 (patch)
treef591efcd4d250d73c4b265e29a1e1fa44b889017 /util/iobuf.c
parentSee ChangeLog: Wed Jan 13 12:49:36 CET 1999 Werner Koch (diff)
downloadgnupg-e99e43cd531c4ba26bb1b2fbc0e356f95126ae24.tar.gz
gnupg-e99e43cd531c4ba26bb1b2fbc0e356f95126ae24.zip
See ChangeLog: Wed Jan 13 14:10:15 CET 1999 Werner Koch
Diffstat (limited to '')
-rw-r--r--util/iobuf.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/util/iobuf.c b/util/iobuf.c
index b6314527a..b62da6dfa 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -550,6 +550,38 @@ iobuf_open( const char *fname )
}
/****************
+ * Create a head iobuf for reading from a file
+ * returns: NULL if an error occures and sets errno
+ */
+IOBUF
+iobuf_fdopen( int fd, const char *mode )
+{
+ IOBUF a;
+ FILE *fp;
+ file_filter_ctx_t *fcx;
+ size_t len;
+
+ if( strchr( mode, 'w' ) )
+ log_bug("iobuf_fdopen: mode `%s' is not supported", mode);
+
+ if( !(fp = fdopen(fd, mode)) )
+ return NULL;
+ a = iobuf_alloc(1, 8192 );
+ fcx = m_alloc( sizeof *fcx + 20 );
+ fcx->fp = fp;
+ fcx->print_only_name = 1;
+ sprintf(fcx->fname, "[fd %d]", fd );
+ a->filter = file_filter;
+ a->filter_ov = fcx;
+ file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
+ file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
+ if( DBG_IOBUF )
+ log_debug("iobuf-%d.%d: fdopen `%s'\n", a->no, a->subno, fcx->fname );
+
+ return a;
+}
+
+/****************
* create an iobuf for writing to a file; the file will be created.
*/
IOBUF