diff options
author | sin <sin@2f30.org> | 2019-08-03 22:30:50 +0100 |
---|---|---|
committer | sin <sin@2f30.org> | 2019-08-03 22:31:34 +0100 |
commit | 1a5eb40d84cc39bdc4420ff3e591068bdfbf6669 (patch) | |
tree | 3aa3a27da5a0b5ad3535f332bbc3cf528cda0703 | |
parent | 50592339bf450037972b85777d1c524e35545aa8 (diff) | |
download | noice-1a5eb40d84cc39bdc4420ff3e591068bdfbf6669.tar.gz |
Factor out dprintf()
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | dprintf.c | 21 | ||||
-rw-r--r-- | noice.c | 16 | ||||
-rw-r--r-- | util.h | 5 |
4 files changed, 25 insertions, 20 deletions
@@ -7,7 +7,7 @@ MANPREFIX = $(PREFIX)/man NOICELDLIBS = -lcurses NOPENLDLIBS = -NOICEOBJ = noice.o spawn.o strlcat.o strlcpy.o strverscmp.o +NOICEOBJ = dprintf.o noice.o spawn.o strlcat.o strlcpy.o strverscmp.o NOPENOBJ = nopen.o spawn.o BIN = noice nopen MAN = noice.1 nopen.1 @@ -20,6 +20,7 @@ noice: $(NOICEOBJ) nopen: $(NOPENOBJ) $(CC) $(CFLAGS) -o $@ $(NOPENOBJ) $(LDFLAGS) $(NOPENLDLIBS) +dprintf.o: util.h noice.o: noiceconf.h util.h nopen.o: nopenconf.h util.h spawn.o: util.h diff --git a/dprintf.c b/dprintf.c new file mode 100644 index 0000000..4bbff79 --- /dev/null +++ b/dprintf.c @@ -0,0 +1,21 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdarg.h> +#include <stdio.h> +#include <unistd.h> + +#include "util.h" + +int +dprintf(int fd, const char *fmt, ...) +{ + char buf[BUFSIZ]; + int r; + va_list ap; + + va_start(ap, fmt); + r = vsnprintf(buf, sizeof(buf), fmt, ap); + if (r > 0) + write(fd, buf, r); + va_end(ap); + return r; +} @@ -11,7 +11,6 @@ #include <locale.h> #include <regex.h> #include <signal.h> -#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -95,21 +94,6 @@ void printmsg(char *); void printwarn(void); void printerr(int, char *); -int -dprintf(int fd, const char *fmt, ...) -{ - char buf[BUFSIZ]; - int r; - va_list ap; - - va_start(ap, fmt); - r = vsnprintf(buf, sizeof(buf), fmt, ap); - if (r > 0) - write(fd, buf, r); - va_end(ap); - return r; -} - void * xmalloc(size_t size) { @@ -17,13 +17,12 @@ #define DPRINTF_LLU(x) #endif /* DEBUG */ +#undef dprintf +int dprintf(int, const char *, ...); #undef strlcat size_t strlcat(char *, const char *, size_t); #undef strlcpy size_t strlcpy(char *, const char *, size_t); -#undef dprintf -int dprintf(int, const char *, ...); - int strverscmp(const char *, const char *); void spawnvp(char *, char *, char *[]); void spawnlp(char *, char *, char *, ...); |