aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--pingu.c25
-rw-r--r--xlib.c31
-rw-r--r--xlib.h8
4 files changed, 42 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index 4500736..2c8fc19 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,9 @@ TARGETS = pingu mtu
CFLAGS ?= -g
pingu_OBJS = \
+ log.o \
pingu.o \
- log.o
+ xlib.o
mtu_OBJS = \
mtu.o
diff --git a/pingu.c b/pingu.c
index 515855b..e708c45 100644
--- a/pingu.c
+++ b/pingu.c
@@ -7,6 +7,7 @@
#include <unistd.h>
#include "pingu.h"
+#include "xlib.h"
int pingu_verbose = 0;
@@ -19,30 +20,6 @@ struct provider {
int status;
};
-void *xmalloc(size_t size)
-{
- void *p = malloc(size);
- if (p == NULL)
- err(EXIT_FAILURE, "malloc");
- return p;
-}
-
-void *xrealloc(void *ptr, size_t size)
-{
- void *p = realloc(ptr, size);
- if (p == NULL)
- err(EXIT_FAILURE, "realloc");
- return p;
-}
-
-char *xstrdup(const char *str)
-{
- char *s = strdup(str);
- if (s == NULL)
- err(EXIT_FAILURE, "strdup");
- return s;
-}
-
#if 0
int skip(char **str, int whitespace)
{
diff --git a/xlib.c b/xlib.c
new file mode 100644
index 0000000..d8392c1
--- /dev/null
+++ b/xlib.c
@@ -0,0 +1,31 @@
+
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "xlib.h"
+
+void *xmalloc(size_t size)
+{
+ void *p = malloc(size);
+ if (p == NULL)
+ err(EXIT_FAILURE, "malloc");
+ return p;
+}
+
+void *xrealloc(void *ptr, size_t size)
+{
+ void *p = realloc(ptr, size);
+ if (p == NULL)
+ err(EXIT_FAILURE, "realloc");
+ return p;
+}
+
+char *xstrdup(const char *str)
+{
+ char *s = strdup(str);
+ if (s == NULL)
+ err(EXIT_FAILURE, "strdup");
+ return s;
+}
+
diff --git a/xlib.h b/xlib.h
new file mode 100644
index 0000000..e6f9e16
--- /dev/null
+++ b/xlib.h
@@ -0,0 +1,8 @@
+#ifndef XLIB_H
+#define XLIB_H
+
+void *xmalloc(size_t size);
+void *xrealloc(void *ptr, size_t size);
+char *xstrdup(const char *str);
+
+#endif