error message style and use strerror in a few places
parent
bd3f7fd842
commit
041912a791
19
st.c
19
st.c
|
@ -256,10 +256,10 @@ xwrite(int fd, const char *s, size_t len)
|
||||||
void *
|
void *
|
||||||
xmalloc(size_t len)
|
xmalloc(size_t len)
|
||||||
{
|
{
|
||||||
void *p = malloc(len);
|
void *p;
|
||||||
|
|
||||||
if (!p)
|
if (!(p = malloc(len)))
|
||||||
die("Out of memory\n");
|
die("malloc: %s\n", strerror(errno));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -268,7 +268,7 @@ void *
|
||||||
xrealloc(void *p, size_t len)
|
xrealloc(void *p, size_t len)
|
||||||
{
|
{
|
||||||
if ((p = realloc(p, len)) == NULL)
|
if ((p = realloc(p, len)) == NULL)
|
||||||
die("Out of memory\n");
|
die("realloc: %s\n", strerror(errno));
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -277,7 +277,7 @@ char *
|
||||||
xstrdup(char *s)
|
xstrdup(char *s)
|
||||||
{
|
{
|
||||||
if ((s = strdup(s)) == NULL)
|
if ((s = strdup(s)) == NULL)
|
||||||
die("Out of memory\n");
|
die("strdup: %s\n", strerror(errno));
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -730,7 +730,7 @@ sigchld(int a)
|
||||||
pid_t p;
|
pid_t p;
|
||||||
|
|
||||||
if ((p = waitpid(pid, &stat, WNOHANG)) < 0)
|
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)
|
if (pid != p)
|
||||||
return;
|
return;
|
||||||
|
@ -781,7 +781,8 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||||
|
|
||||||
if (line) {
|
if (line) {
|
||||||
if ((cmdfd = open(line, O_RDWR)) < 0)
|
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);
|
dup2(cmdfd, 0);
|
||||||
stty(args);
|
stty(args);
|
||||||
return cmdfd;
|
return cmdfd;
|
||||||
|
@ -793,7 +794,7 @@ ttynew(char *line, char *cmd, char *out, char **args)
|
||||||
|
|
||||||
switch (pid = fork()) {
|
switch (pid = fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
die("fork failed\n");
|
die("fork failed: %s\n", strerror(errno));
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
close(iofd);
|
close(iofd);
|
||||||
|
@ -826,7 +827,7 @@ ttyread(void)
|
||||||
|
|
||||||
/* append read bytes to unprocessed bytes */
|
/* append read bytes to unprocessed bytes */
|
||||||
if ((ret = read(cmdfd, buf+buflen, LEN(buf)-buflen)) < 0)
|
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;
|
buflen += ret;
|
||||||
|
|
||||||
written = twrite(buf, buflen, 0);
|
written = twrite(buf, buflen, 0);
|
||||||
|
|
27
x.c
27
x.c
|
@ -742,9 +742,9 @@ xloadcols(void)
|
||||||
for (i = 0; i < dc.collen; i++)
|
for (i = 0; i < dc.collen; i++)
|
||||||
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
if (!xloadcolor(i, NULL, &dc.col[i])) {
|
||||||
if (colorname[i])
|
if (colorname[i])
|
||||||
die("Could not allocate color '%s'\n", colorname[i]);
|
die("could not allocate color '%s'\n", colorname[i]);
|
||||||
else
|
else
|
||||||
die("Could not allocate color %d\n", i);
|
die("could not allocate color %d\n", i);
|
||||||
}
|
}
|
||||||
loaded = 1;
|
loaded = 1;
|
||||||
}
|
}
|
||||||
|
@ -869,7 +869,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
||||||
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
|
if ((XftPatternGetInteger(f->match->pattern, "slant", 0,
|
||||||
&haveattr) != XftResultMatch) || haveattr < wantattr) {
|
&haveattr) != XftResultMatch) || haveattr < wantattr) {
|
||||||
f->badslant = 1;
|
f->badslant = 1;
|
||||||
fputs("st: font slant does not match\n", stderr);
|
fputs("font slant does not match\n", stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -878,7 +878,7 @@ xloadfont(Font *f, FcPattern *pattern)
|
||||||
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
|
if ((XftPatternGetInteger(f->match->pattern, "weight", 0,
|
||||||
&haveattr) != XftResultMatch) || haveattr != wantattr) {
|
&haveattr) != XftResultMatch) || haveattr != wantattr) {
|
||||||
f->badweight = 1;
|
f->badweight = 1;
|
||||||
fputs("st: font weight does not match\n", stderr);
|
fputs("font weight does not match\n", stderr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,14 +906,13 @@ xloadfonts(char *fontstr, double fontsize)
|
||||||
FcPattern *pattern;
|
FcPattern *pattern;
|
||||||
double fontval;
|
double fontval;
|
||||||
|
|
||||||
if (fontstr[0] == '-') {
|
if (fontstr[0] == '-')
|
||||||
pattern = XftXlfdParse(fontstr, False, False);
|
pattern = XftXlfdParse(fontstr, False, False);
|
||||||
} else {
|
else
|
||||||
pattern = FcNameParse((FcChar8 *)fontstr);
|
pattern = FcNameParse((FcChar8 *)fontstr);
|
||||||
}
|
|
||||||
|
|
||||||
if (!pattern)
|
if (!pattern)
|
||||||
die("st: can't open font %s\n", fontstr);
|
die("can't open font %s\n", fontstr);
|
||||||
|
|
||||||
if (fontsize > 1) {
|
if (fontsize > 1) {
|
||||||
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
FcPatternDel(pattern, FC_PIXEL_SIZE);
|
||||||
|
@ -939,7 +938,7 @@ xloadfonts(char *fontstr, double fontsize)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xloadfont(&dc.font, pattern))
|
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) {
|
if (usedfontsize < 0) {
|
||||||
FcPatternGetDouble(dc.font.match->pattern,
|
FcPatternGetDouble(dc.font.match->pattern,
|
||||||
|
@ -956,17 +955,17 @@ xloadfonts(char *fontstr, double fontsize)
|
||||||
FcPatternDel(pattern, FC_SLANT);
|
FcPatternDel(pattern, FC_SLANT);
|
||||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ITALIC);
|
||||||
if (xloadfont(&dc.ifont, pattern))
|
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);
|
FcPatternDel(pattern, FC_WEIGHT);
|
||||||
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
FcPatternAddInteger(pattern, FC_WEIGHT, FC_WEIGHT_BOLD);
|
||||||
if (xloadfont(&dc.ibfont, pattern))
|
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);
|
FcPatternDel(pattern, FC_SLANT);
|
||||||
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
FcPatternAddInteger(pattern, FC_SLANT, FC_SLANT_ROMAN);
|
||||||
if (xloadfont(&dc.bfont, pattern))
|
if (xloadfont(&dc.bfont, pattern))
|
||||||
die("st: can't open font %s\n", fontstr);
|
die("can't open font %s\n", fontstr);
|
||||||
|
|
||||||
FcPatternDestroy(pattern);
|
FcPatternDestroy(pattern);
|
||||||
}
|
}
|
||||||
|
@ -1003,13 +1002,13 @@ xinit(int cols, int rows)
|
||||||
XColor xmousefg, xmousebg;
|
XColor xmousefg, xmousebg;
|
||||||
|
|
||||||
if (!(xw.dpy = XOpenDisplay(NULL)))
|
if (!(xw.dpy = XOpenDisplay(NULL)))
|
||||||
die("Can't open display\n");
|
die("can't open display\n");
|
||||||
xw.scr = XDefaultScreen(xw.dpy);
|
xw.scr = XDefaultScreen(xw.dpy);
|
||||||
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
xw.vis = XDefaultVisual(xw.dpy, xw.scr);
|
||||||
|
|
||||||
/* font */
|
/* font */
|
||||||
if (!FcInit())
|
if (!FcInit())
|
||||||
die("Could not init fontconfig.\n");
|
die("could not init fontconfig.\n");
|
||||||
|
|
||||||
usedfont = (opt_font == NULL)? font : opt_font;
|
usedfont = (opt_font == NULL)? font : opt_font;
|
||||||
xloadfonts(usedfont, 0);
|
xloadfonts(usedfont, 0);
|
||||||
|
|
Reference in New Issue