summaryrefslogtreecommitdiff
path: root/lib/fstream/printf.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-04 18:26:16 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-16 09:34:35 +0200
commit1e255d0f6c472bb3c710aea1ea8dc5d27c0fba4a (patch)
tree0ba8dfc243a00ef955da973b1615a95498579525 /lib/fstream/printf.c
parentb96f0fc154feef531be76034bf6e38925636146f (diff)
Add stream I/O abstraction library
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/fstream/printf.c')
-rw-r--r--lib/fstream/printf.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/fstream/printf.c b/lib/fstream/printf.c
new file mode 100644
index 0000000..3850487
--- /dev/null
+++ b/lib/fstream/printf.c
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-3.0-or-later */
+/*
+ * printf.c
+ *
+ * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at>
+ */
+#include "internal.h"
+
+int ostream_printf(ostream_t *strm, const char *fmt, ...)
+{
+ char *temp = NULL;
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+
+ ret = vasprintf(&temp, fmt, ap);
+ if (ret < 0)
+ perror(strm->get_filename(strm));
+ va_end(ap);
+
+ if (ret < 0)
+ return -1;
+
+ if (strm->append(strm, temp, ret))
+ ret = -1;
+
+ free(temp);
+ return ret;
+}