[hackers] [st] error message style and use strerror in a few places || Hiltjo Posthuma

From: <git_AT_suckless.org>
Date: Thu, 29 Mar 2018 18:42:08 +0200 (CEST)

commit 041912a791e8c2f4d5d2415b16210d29d7e701c5
Author: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
AuthorDate: Thu Mar 29 18:30:05 2018 +0200
Commit: Hiltjo Posthuma <hiltjo_AT_codemadness.org>
CommitDate: Thu Mar 29 18:30:05 2018 +0200

    error message style and use strerror in a few places

diff --git a/st.c b/st.c
index 2612c95..0628707 100644
--- a/st.c
+++ b/st.c
_AT_@ -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;
 }
_AT_@ -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;
 }
_AT_@ -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;
 }
_AT_@ -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");
         }
_AT_@ -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;
_AT_@ -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;
_AT_@ -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);
_AT_@ -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);
diff --git a/x.c b/x.c
index f0195c9..c0bd890 100644
--- a/x.c
+++ b/x.c
_AT_@ -742,9 +742,9 @@ xloadcols(void)
         for (i = 0; i < dc.collen; i++)
                 if (!xloadcolor(i, NULL, &dc.col[i])) {
                         if (colorname[i])
- die("Could not allocate color '%s'\n", colorname[i]);
+ die("could not allocate color '%s'\n", colorname[i]);
                         else
- die("Could not allocate color %d\n", i);
+ die("could not allocate color %d\n", i);
                 }
         loaded = 1;
 }
_AT_@ -869,7 +869,7 @@ xloadfont(Font *f, FcPattern *pattern)
                 if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
                     &haveattr) != XftResultMatch) || haveattr < wantattr) {
                         f->badslant = 1;
- fputs("st: font slant does not match\n", stderr);
+ fputs("font slant does not match\n", stderr);
                 }
         }
 
_AT_@ -878,7 +878,7 @@ xloadfont(Font *f, FcPattern *pattern)
                 if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
                     &haveattr) != XftResultMatch) || haveattr != wantattr) {
                         f->badweight = 1;
- fputs("st: font weight does not match\n", stderr);
+ fputs("font weight does not match\n", stderr);
                 }
         }
 
_AT_@ -906,14 +906,13 @@ xloadfonts(char *fontstr, double fontsize)
         FcPattern *pattern;
         double fontval;
 
- if (fontstr[0] == '-') {
+ if (fontstr[0] == '-')
                 pattern = XftXlfdParse(fontstr, False, False);
- } else {
+ else
                 pattern = FcNameParse((FcChar8 *)fontstr);
- }
 
         if (!pattern)
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
 
         if (fontsize > 1) {
                 FcPatternDel(pattern, FC_PIXEL_SIZE);
_AT_@ -939,7 +938,7 @@ xloadfonts(char *fontstr, double fontsize)
         }
 
         if (xloadfont(&dc.font, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
 
         if (usedfontsize < 0) {
                 FcPatternGetDouble(dc.font.match->pattern,
_AT_@ -956,17 +955,17 @@ xloadfonts(char *fontstr, double fontsize)
         FcPatternDel(pattern, FC_SLANT);
         FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
         if (xloadfont(&dc.ifont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
 
         FcPatternDel(pattern, FC_WEIGHT);
         FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
         if (xloadfont(&dc.ibfont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
 
         FcPatternDel(pattern, FC_SLANT);
         FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
         if (xloadfont(&dc.bfont, pattern))
- die("st: can't open font %s\n", fontstr);
+ die("can't open font %s\n", fontstr);
 
         FcPatternDestroy(pattern);
 }
_AT_@ -1003,13 +1002,13 @@ xinit(int cols, int rows)
         XColor xmousefg, xmousebg;
 
         if (!(xw.dpy = XOpenDisplay(NULL)))
- die("Can't open display\n");
+ die("can't open display\n");
         xw.scr = XDefaultScreen(xw.dpy);
         xw.vis = XDefaultVisual(xw.dpy, xw.scr);
 
         /* font */
         if (!FcInit())
- die("Could not init fontconfig.\n");
+ die("could not init fontconfig.\n");
 
         usedfont = (opt_font == NULL)? font : opt_font;
         xloadfonts(usedfont, 0);
Received on Thu Mar 29 2018 - 18:42:08 CEST

This archive was generated by hypermail 2.3.0 : Thu Mar 29 2018 - 18:48:41 CEST