diff options
author | Andrew Tridgell <tridge@samba.org> | 2010-02-11 20:18:50 +1100 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2010-02-11 21:04:13 +1100 |
commit | d6fb64c51244529388b1f79ba8220ff608e1e4de (patch) | |
tree | a251db001e467af5a8d833bc29621f8d6a305cde /lib/replace/replace.c | |
parent | c986bfb22ec6ee1bda8a7c4053770831f582cbb3 (diff) | |
download | samba-d6fb64c51244529388b1f79ba8220ff608e1e4de.tar.gz samba-d6fb64c51244529388b1f79ba8220ff608e1e4de.tar.bz2 samba-d6fb64c51244529388b1f79ba8220ff608e1e4de.zip |
libreplace: added replacements for dprintf() and vdprintf()
these are very useful for writing files with formatted writes
Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>
Diffstat (limited to 'lib/replace/replace.c')
-rw-r--r-- | lib/replace/replace.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/replace/replace.c b/lib/replace/replace.c index df29185564..6f0851da7c 100644 --- a/lib/replace/replace.c +++ b/lib/replace/replace.c @@ -704,3 +704,34 @@ void *rep_memmem(const void *haystack, size_t haystacklen, } #endif +#ifndef HAVE_VDPRINTF +int vdprintf(int fd, const char *format, va_list ap) +{ + char *s = NULL; + int ret; + + vasprintf(&s, format, ap); + if (s == NULL) { + errno = ENOMEM; + return -1; + } + ret = write(fd, s, strlen(s)); + free(s); + return ret; +} +#endif + +#ifndef HAVE_DPRINTF +int dprintf(int fd, const char *format, ...) +{ + int ret; + va_list ap; + + va_start(ap, format); + ret = vdprintf(fd, format, ap); + va_end(ap); + + return ret; +} +#endif + |