noice

small file browser
git clone git://git.2f30.org/noice
Log | Files | Refs | README | LICENSE

commit 1a5eb40d84cc39bdc4420ff3e591068bdfbf6669
parent 50592339bf450037972b85777d1c524e35545aa8
Author: sin <sin@2f30.org>
Date:   Sat,  3 Aug 2019 22:30:50 +0100

Factor out dprintf()

Diffstat:
MMakefile | 3++-
Adprintf.c | 21+++++++++++++++++++++
Mnoice.c | 16----------------
Mutil.h | 5++---
4 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/Makefile b/Makefile @@ -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 @@ -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; +} diff --git a/noice.c b/noice.c @@ -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) { diff --git a/util.h b/util.h @@ -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 *, ...);