aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2019-08-03 22:30:50 +0100
committersin <sin@2f30.org>2019-08-03 22:31:34 +0100
commit1a5eb40d84cc39bdc4420ff3e591068bdfbf6669 (patch)
tree3aa3a27da5a0b5ad3535f332bbc3cf528cda0703
parent50592339bf450037972b85777d1c524e35545aa8 (diff)
downloadnoice-1a5eb40d84cc39bdc4420ff3e591068bdfbf6669.tar.gz
Factor out dprintf()
-rw-r--r--Makefile3
-rw-r--r--dprintf.c21
-rw-r--r--noice.c16
-rw-r--r--util.h5
4 files changed, 25 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index 67efb04..6fc286b 100644
--- 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
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;
+}
diff --git a/noice.c b/noice.c
index ba23f9d..b73f1ea 100644
--- 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
index f80dc89..0ccdb50 100644
--- 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 *, ...);
Un proyecto texto-plano.xyz