diff options
author | Hiltjo Posthuma <hiltjo@codemadness.org> | 2018-03-29 18:30:05 +0200 |
---|---|---|
committer | Hiltjo Posthuma <hiltjo@codemadness.org> | 2018-03-29 18:30:05 +0200 |
commit | 041912a791e8c2f4d5d2415b16210d29d7e701c5 (patch) | |
tree | 273e96d51d3d3ee99f5c540a873ab8da121f3590 /st.c | |
parent | bd3f7fd84270025696790512cf3c2dafaf5bc77f (diff) | |
download | st-041912a791e8c2f4d5d2415b16210d29d7e701c5.tar.gz st-041912a791e8c2f4d5d2415b16210d29d7e701c5.tar.bz2 |
error message style and use strerror in a few places
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 21 |
1 files changed, 11 insertions, 10 deletions
@@ -256,10 +256,10 @@ xwrite(int fd, const char *s, size_t len) void * xmalloc(size_t len) { - void *p = malloc(len); + void *p; - if (!p) - die("Out of memory\n"); + if (!(p = malloc(len))) + die("malloc: %s\n", strerror(errno)); return p; } @@ -268,7 +268,7 @@ void * xrealloc(void *p, size_t len) { if ((p = realloc(p, len)) == NULL) - die("Out of memory\n"); + die("realloc: %s\n", strerror(errno)); return p; } @@ -277,7 +277,7 @@ char * xstrdup(char *s) { if ((s = strdup(s)) == NULL) - die("Out of memory\n"); + die("strdup: %s\n", strerror(errno)); return s; } @@ -687,7 +687,7 @@ execsh(char *cmd, char **args) errno = 0; if ((pw = getpwuid(getuid())) == NULL) { if (errno) - die("getpwuid:%s\n", strerror(errno)); + die("getpwuid: %s\n", strerror(errno)); else die("who are you?\n"); } @@ -730,7 +730,7 @@ sigchld(int a) pid_t p; if ((p = waitpid(pid, &stat, WNOHANG)) < 0) - die("Waiting for pid %hd failed: %s\n", pid, strerror(errno)); + die("waiting for pid %hd failed: %s\n", pid, strerror(errno)); if (pid != p) return; @@ -781,7 +781,8 @@ ttynew(char *line, char *cmd, char *out, char **args) if (line) { if ((cmdfd = open(line, O_RDWR)) < 0) - die("open line failed: %s\n", strerror(errno)); + die("open line '%s' failed: %s\n", + line, strerror(errno)); dup2(cmdfd, 0); stty(args); return cmdfd; @@ -793,7 +794,7 @@ ttynew(char *line, char *cmd, char *out, char **args) switch (pid = fork()) { case -1: - die("fork failed\n"); + die("fork failed: %s\n", strerror(errno)); break; case 0: close(iofd); @@ -826,7 +827,7 @@ ttyread(void) /* append read bytes to unprocessed bytes */ if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0) - die("Couldn't read from shell: %s\n", strerror(errno)); + die("couldn't read from shell: %s\n", strerror(errno)); buflen += ret; written = twrite(buf, buflen, 0); |