aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--pty.c1
-rw-r--r--st.c1
-rw-r--r--std.c39
-rw-r--r--util.c37
-rw-r--r--util.h5
6 files changed, 46 insertions, 39 deletions
diff --git a/Makefile b/Makefile
index cf1766c..dcbbbcf 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = st.c std.c 6SRC = st.c std.c util.c pty.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options st 9all: options st
diff --git a/pty.c b/pty.c
index bf0b0f7..4c38d86 100644
--- a/pty.c
+++ b/pty.c
@@ -1,4 +1,5 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include "util.h"
2#include <sys/types.h> 3#include <sys/types.h>
3#include <sys/stat.h> 4#include <sys/stat.h>
4#include <fcntl.h> 5#include <fcntl.h>
diff --git a/st.c b/st.c
index a3421ff..8dd7793 100644
--- a/st.c
+++ b/st.c
@@ -1,4 +1,5 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include "util.h"
2#include <stdio.h> 3#include <stdio.h>
3 4
4int 5int
diff --git a/std.c b/std.c
index 3fd07a4..a7b2f4a 100644
--- a/std.c
+++ b/std.c
@@ -1,12 +1,8 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include <sys/ioctl.h> 2#include "util.h"
3#include <sys/select.h>
4#include <sys/stat.h>
5#include <sys/types.h> 3#include <sys/types.h>
6#include <sys/wait.h> 4#include <sys/wait.h>
7#include <ctype.h> 5#include <ctype.h>
8#include <errno.h>
9#include <fcntl.h>
10#include <signal.h> 6#include <signal.h>
11#include <stdarg.h> 7#include <stdarg.h>
12#include <stdio.h> 8#include <stdio.h>
@@ -20,9 +16,6 @@
20 16
21void buffer(char c); 17void buffer(char c);
22void cmd(const char *cmdstr, ...); 18void cmd(const char *cmdstr, ...);
23void *emallocz(unsigned int size);
24void eprint(const char *errstr, ...);
25void eprintn(const char *errstr, ...);
26void getpty(void); 19void getpty(void);
27void movea(int x, int y); 20void movea(int x, int y);
28void mover(int x, int y); 21void mover(int x, int y);
@@ -68,36 +61,6 @@ cmd(const char *cmdstr, ...) {
68 va_end(ap); 61 va_end(ap);
69} 62}
70 63
71void *
72emallocz(unsigned int size) {
73 void *res = calloc(1, size);
74
75 if(!res)
76 eprint("fatal: could not malloc() %u bytes\n", size);
77 return res;
78}
79
80void
81eprint(const char *errstr, ...) {
82 va_list ap;
83
84 va_start(ap, errstr);
85 vfprintf(stderr, errstr, ap);
86 va_end(ap);
87 exit(EXIT_FAILURE);
88}
89
90void
91eprintn(const char *errstr, ...) {
92 va_list ap;
93
94 va_start(ap, errstr);
95 vfprintf(stderr, errstr, ap);
96 va_end(ap);
97 fprintf(stderr, ": %s\n", strerror(errno));
98 exit(EXIT_FAILURE);
99}
100
101void 64void
102movea(int x, int y) { 65movea(int x, int y) {
103 x = MAX(x, cols); 66 x = MAX(x, cols);
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..f8b9eee
--- /dev/null
+++ b/util.c
@@ -0,0 +1,37 @@
1/* See LICENSE file for copyright and license details. */
2#include "util.h"
3#include <errno.h>
4#include <stdarg.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <string.h>
8
9void *
10emallocz(unsigned int size) {
11 void *res = calloc(1, size);
12
13 if(!res)
14 eprint("fatal: could not malloc() %u bytes\n", size);
15 return res;
16}
17
18void
19eprint(const char *errstr, ...) {
20 va_list ap;
21
22 va_start(ap, errstr);
23 vfprintf(stderr, errstr, ap);
24 va_end(ap);
25 exit(EXIT_FAILURE);
26}
27
28void
29eprintn(const char *errstr, ...) {
30 va_list ap;
31
32 va_start(ap, errstr);
33 vfprintf(stderr, errstr, ap);
34 va_end(ap);
35 fprintf(stderr, ": %s\n", strerror(errno));
36 exit(EXIT_FAILURE);
37}
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..34db193
--- /dev/null
+++ b/util.h
@@ -0,0 +1,5 @@
1/* See LICENSE file for copyright and license details. */
2
3void *emallocz(unsigned int size);
4void eprint(const char *errstr, ...);
5void eprintn(const char *errstr, ...);