1
0
mirror of https://github.com/openbsd/src.git synced 2024-12-22 16:42:56 -08:00

Use errc/warnc to simplify code.

Also, in 'ftp', always put the error message last, after the hostname/ipaddr.

ok jsing@ krw@ millert@
This commit is contained in:
guenther 2014-05-20 01:25:23 +00:00
parent 537292fc48
commit 5ad04d3516
34 changed files with 124 additions and 134 deletions

View File

@ -36,10 +36,10 @@ thread(void *arg)
int r;
if ((r = pthread_rwlock_rdlock(&start)))
errx(1, "could not obtain lock in thread: %s", strerror(r));
errc(1, r, "could not obtain lock in thread");
real_func(arg);
if ((r = pthread_rwlock_unlock(&start)))
errx(1, "could not release lock in thread: %s", strerror(r));
errc(1, r, "could not release lock in thread");
return NULL;
}
@ -52,20 +52,20 @@ run_threads(void (*func)(void *), void *arg)
self = pthread_self();
real_func = func;
if ((r = pthread_rwlock_init(&start, NULL)))
errx(1, "could not initialize lock: %s", strerror(r));
errc(1, r, "could not initialize lock");
if ((r = pthread_rwlock_wrlock(&start))) /* block */
errx(1, "could not lock lock: %s", strerror(r));
errc(1, r, "could not lock lock");
for (i = 0; i < THREAD_COUNT; i++)
if ((r = pthread_create(&pthread[i], NULL, thread, arg))) {
warnx("could not create thread: %s", strerror(r));
warnc(r, "could not create thread");
pthread[i] = self;
}
if ((r = pthread_rwlock_unlock(&start))) /* unleash */
errx(1, "could not release lock: %s", strerror(r));
errc(1, r, "could not release lock");
sleep(1);
@ -76,6 +76,6 @@ run_threads(void (*func)(void *), void *arg)
for (i = 0; i < THREAD_COUNT; i++)
if (! pthread_equal(pthread[i], self) &&
(r = pthread_join(pthread[i], NULL)))
warnx("could not join thread: %s", strerror(r));
warnc(r, "could not join thread");
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: earlysig.c,v 1.1 2013/06/21 06:47:20 guenther Exp $ */
/* $OpenBSD: earlysig.c,v 1.2 2014/05/20 01:25:24 guenther Exp $ */
/*
* Public domain. 2005, Otto Moerbeek; 2013, Philip Guenther
@ -43,7 +43,7 @@ main()
/* make sure the thread library is fully active */
if ((r = pthread_create(&tid, NULL, tmain, NULL)))
errx(1, "pthread_create: %s", strerror(r));
errc(1, r, "pthread_create");
pthread_join(tid, NULL);
/* make sure kill() and all the symbols in fork() are bound */

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pthread_rwlock.c,v 1.2 2012/02/26 11:47:51 miod Exp $ */
/* $OpenBSD: pthread_rwlock.c,v 1.3 2014/05/20 01:25:24 guenther Exp $ */
/* PUBLIC DOMAIN Feb 2012 <guenther@openbsd.org> */
#include <sys/types.h>
@ -132,11 +132,11 @@ main(void)
for (i = 0; i < NUM_READERS; i++) {
ids[i] = i;
if ((r = pthread_create(&tr[i], NULL, reader, &ids[i])))
errx(1, "create %d: %s", i, strerror(r));
errc(1, r, "create %d", i);
}
if ((r = pthread_create(&tw, NULL, writer, NULL)))
errx(1, "create writer: %s", strerror(r));
errc(1, r, "create writer");
pthread_mutex_lock(&m);
while (state != WRITE)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: main-thread-exited.c,v 1.1 2012/03/05 02:40:21 guenther Exp $ */
/* $OpenBSD: main-thread-exited.c,v 1.2 2014/05/20 01:25:24 guenther Exp $ */
/* PUBLIC DOMAIN Mar 2012 <guenther@openbsd.org> */
@ -44,7 +44,7 @@ main(int argc, char **argv)
/* in child */
if ((r = pthread_create(&t, NULL, tmain, NULL)))
errx(1, "pthread_create: %s", strerror(r));
errc(1, r, "pthread_create");
pthread_exit(NULL);
abort();
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: rlim-file.c,v 1.3 2003/07/31 21:48:10 deraadt Exp $ */
/* $OpenBSD: rlim-file.c,v 1.4 2014/05/20 01:25:24 guenther Exp $ */
/*
* Written by Artur Grabowski <art@openbsd.org> (2002) Public Domain.
*/
@ -34,7 +34,7 @@ main(int argc, char *argv[])
errx(1, "try to do the test on a less loaded system");
if (errno != EMFILE)
errx(1, "bad errno (%d): %s", errno, strerror(errno));
err(1, "bad errno (%d)", errno);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: csplit.c,v 1.4 2012/03/04 04:05:15 fgsch Exp $ */
/* $OpenBSD: csplit.c,v 1.5 2014/05/20 01:25:23 guenther Exp $ */
/* $FreeBSD: src/usr.bin/csplit/csplit.c,v 1.9 2004/03/22 11:15:03 tjr Exp $ */
/*-
@ -239,7 +239,7 @@ newfile(void)
if ((size_t)snprintf(currfile, sizeof(currfile), "%s%0*ld", prefix,
(int)sufflen, nfiles) >= sizeof(currfile))
errx(1, "%s: %s", currfile, strerror(ENAMETOOLONG));
errc(1, ENAMETOOLONG, "%s", currfile);
if ((fp = fopen(currfile, "w+")) == NULL)
err(1, "%s", currfile);
nfiles++;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: dc.c,v 1.11 2009/10/27 23:59:37 deraadt Exp $ */
/* $OpenBSD: dc.c,v 1.12 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 2003, Otto Moerbeek <otto@drijf.net>
@ -91,10 +91,8 @@ main(int argc, char *argv[])
err(1, "cannot open file %s", argv[0]);
if (fstat(fileno(file), &st) == -1)
err(1, "%s", argv[0]);
if (S_ISDIR(st.st_mode)) {
errno = EISDIR;
err(1, "%s", argv[0]);
}
if (S_ISDIR(st.st_mode))
errc(1, EISDIR, "%s", argv[0]);
src_setstream(&src, file);
reset_bmachine(&src);
eval();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: diffdir.c,v 1.41 2012/11/29 02:15:44 guenther Exp $ */
/* $OpenBSD: diffdir.c,v 1.42 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 2003, 2010 Todd C. Miller <Todd.Miller@courtesan.com>
@ -56,7 +56,7 @@ diffdir(char *p1, char *p2, int flags)
dirlen1 = strlcpy(path1, *p1 ? p1 : ".", sizeof(path1));
if (dirlen1 >= sizeof(path1) - 1) {
warnx("%s: %s", p1, strerror(ENAMETOOLONG));
warnc(ENAMETOOLONG, "%s", p1);
status = 2;
return;
}
@ -66,7 +66,7 @@ diffdir(char *p1, char *p2, int flags)
}
dirlen2 = strlcpy(path2, *p2 ? p2 : ".", sizeof(path2));
if (dirlen2 >= sizeof(path2) - 1) {
warnx("%s: %s", p2, strerror(ENAMETOOLONG));
warnc(ENAMETOOLONG, "%s", p2);
status = 2;
return;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: du.c,v 1.24 2013/11/13 21:20:01 deraadt Exp $ */
/* $OpenBSD: du.c,v 1.25 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: du.c,v 1.11 1996/10/18 07:20:35 thorpej Exp $ */
/*
@ -183,7 +183,7 @@ main(int argc, char *argv[])
case FTS_DNR: /* Warn, continue. */
case FTS_ERR:
case FTS_NS:
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
warnc(p->fts_errno, "%s", p->fts_path);
rval = 1;
break;
default:

View File

@ -1,4 +1,4 @@
/* $OpenBSD: fetch.c,v 1.121 2014/05/19 20:09:22 jca Exp $ */
/* $OpenBSD: fetch.c,v 1.122 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */
/*-
@ -723,7 +723,7 @@ noslash:
#endif /* !SMALL */
}
if (error) {
warnx("%s: %s", gai_strerror(error), host);
warnx("%s: %s", host, gai_strerror(error));
goto cleanup_url_get;
}
@ -732,7 +732,7 @@ noslash:
hints.ai_flags |= AI_NUMERICHOST;
error = getaddrinfo(srcaddr, NULL, &hints, &ares);
if (error) {
warnx("%s: %s", gai_strerror(error), srcaddr);
warnx("%s: %s", srcaddr, gai_strerror(error));
goto cleanup_url_get;
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ftp.c,v 1.85 2014/04/22 20:48:41 tedu Exp $ */
/* $OpenBSD: ftp.c,v 1.86 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */
/*
@ -176,7 +176,7 @@ hookup(char *host, char *port)
error = getaddrinfo(srcaddr, NULL, &ahints, &ares);
if (error) {
warnx("%s: %s", gai_strerror(error), srcaddr);
warnx("%s: %s", srcaddr, gai_strerror(error));
code = -1;
return (0);
}
@ -781,10 +781,10 @@ sendrequest(const char *cmd, const char *local, const char *remote,
(void)fflush(ttyout);
}
if (c < 0)
warnx("local: %s: %s", local, strerror(serrno));
warnc(serrno, "local: %s", local);
if (d < 0) {
if (serrno != EPIPE)
warnx("netout: %s", strerror(serrno));
warnc(serrno, "netout");
bytes = -1;
}
break;
@ -822,10 +822,10 @@ sendrequest(const char *cmd, const char *local, const char *remote,
(void)fflush(ttyout);
}
if (ferror(fin))
warnx("local: %s: %s", local, strerror(serrno));
warnc(serrno, "local: %s", local);
if (ferror(dout)) {
if (errno != EPIPE)
warnx("netout: %s", strerror(serrno));
warnc(serrno, "netout");
bytes = -1;
}
break;
@ -1118,12 +1118,12 @@ recvrequest(const char *cmd, const char * volatile local, const char *remote,
}
if (c < 0) {
if (serrno != EPIPE)
warnx("netin: %s", strerror(serrno));
warnc(serrno, "netin");
bytes = -1;
}
if (d < c) {
if (d < 0)
warnx("local: %s: %s", local, strerror(serrno));
warnc(serrno, "local: %s", local);
else
warnx("%s: short write", local);
}
@ -1203,11 +1203,11 @@ break2:
}
if (ferror(din)) {
if (serrno != EPIPE)
warnx("netin: %s", strerror(serrno));
warnc(serrno, "netin");
bytes = -1;
}
if (ferror(fout))
warnx("local: %s: %s", local, strerror(serrno));
warnc(serrno, "local: %s", local);
break;
}
progressmeter(1, NULL);
@ -1305,7 +1305,7 @@ initconn(void)
error = getaddrinfo(srcaddr, NULL, &ahints, &ares);
if (error) {
warnx("%s: %s", gai_strerror(error), srcaddr);
warnx("%s: %s", srcaddr, gai_strerror(error));
code = -1;
return (0);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: ruserpass.c,v 1.28 2009/05/05 19:35:30 martynas Exp $ */
/* $OpenBSD: ruserpass.c,v 1.29 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: ruserpass.c,v 1.14 1997/07/20 09:46:01 lukem Exp $ */
/*
@ -85,7 +85,7 @@ ruserpass(const char *host, char **aname, char **apass, char **aacct)
return (0);
i = snprintf(buf, sizeof(buf), "%s/.netrc", hdir);
if (i < 0 || i >= sizeof(buf)) {
warnx("%s/.netrc: %s", hdir, strerror(ENAMETOOLONG));
warnc(ENAMETOOLONG, "%s/.netrc", hdir);
return (0);
}
cfile = fopen(buf, "r");

View File

@ -1,4 +1,4 @@
/* $OpenBSD: util.c,v 1.47 2013/11/26 13:21:16 deraadt Exp $ */
/* $OpenBSD: util.c,v 1.48 2014/05/20 01:25:23 guenther Exp $ */
/*-
* Copyright (c) 1999 James Howard and Dag-Erling Coïdan Smørgrav
@ -74,7 +74,7 @@ grep_tree(char **argv)
case FTS_ERR:
file_err = 1;
if(!sflag)
warnx("%s: %s", p->fts_path, strerror(p->fts_errno));
warnc(p->fts_errno, "%s", p->fts_path);
break;
case FTS_DP:
break;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: args.c,v 1.17 2013/11/26 13:21:17 deraadt Exp $ */
/* $OpenBSD: args.c,v 1.18 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1980, 1993
@ -168,7 +168,7 @@ set_profile(void)
home = getenv("HOME");
if (home != NULL && *home != '\0') {
if (snprintf(fname, sizeof fname, "%s/%s", home, prof) >= sizeof fname) {
warnx("%s/%s: %s", home, prof, strerror(ENAMETOOLONG));
warnc(ENAMETOOLONG, "%s/%s", home, prof);
return;
}
if ((f = fopen(option_source = fname, "r")) != NULL) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: indent.c,v 1.23 2013/11/26 13:21:17 deraadt Exp $ */
/* $OpenBSD: indent.c,v 1.24 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1980, 1993
@ -1179,7 +1179,7 @@ bakcopy(void)
if (*p == '/')
p++;
if (snprintf(bakfile, MAXPATHLEN, "%s.BAK", p) >= MAXPATHLEN)
errx(1, "%s.BAK: %s", p, strerror(ENAMETOOLONG));
errc(1, ENAMETOOLONG, "%s.BAK", p);
/* copy in_name to backup file */
bakchn = creat(bakfile, 0600);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: lndir.c,v 1.19 2010/08/22 21:25:37 tedu Exp $ */
/* $OpenBSD: lndir.c,v 1.20 2014/05/20 01:25:23 guenther Exp $ */
/* $XConsortium: lndir.c /main/15 1995/08/30 10:56:18 gildea $ */
/*
@ -118,7 +118,7 @@ main(int argc, char *argv[])
if (stat(tn, &ts) < 0)
err(1, "%s", tn);
if (!(S_ISDIR(ts.st_mode)))
errx(2, "%s: %s", tn, strerror(ENOTDIR));
errc(2, ENOTDIR, "%s", tn);
if (chdir(tn) < 0)
err(1, "%s", tn);
@ -126,7 +126,7 @@ main(int argc, char *argv[])
if (stat(fn, &fs) < 0)
err(1, "%s", fn);
if (!(S_ISDIR(fs.st_mode)))
errx(2, "%s: %s", fn, strerror(ENOTDIR));
errc(2, ENOTDIR, "%s", fn);
exit(dodir(fn, &fs, &ts, 0));
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: login.c,v 1.61 2009/10/27 23:59:40 deraadt Exp $ */
/* $OpenBSD: login.c,v 1.62 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: login.c,v 1.13 1996/05/15 23:50:16 jtc Exp $ */
/*-
@ -189,7 +189,7 @@ main(int argc, char *argv[])
break;
case 'h':
if (uid) {
warnx("-h option: %s", strerror(EPERM));
warnc(EPERM, "-h option");
quickexit(1);
}
free(fqdn);
@ -206,7 +206,7 @@ main(int argc, char *argv[])
break;
case 'L':
if (uid) {
warnx("-L option: %s", strerror(EPERM));
warnc(EPERM, "-L option");
quickexit(1);
}
if (lipaddr) {
@ -231,7 +231,7 @@ main(int argc, char *argv[])
break;
case 'R':
if (uid) {
warnx("-R option: %s", strerror(EPERM));
warnc(EPERM, "-R option");
quickexit(1);
}
if (ripaddr) {
@ -243,7 +243,7 @@ main(int argc, char *argv[])
break;
case 'u':
if (uid) {
warnx("-u option: %s", strerror(EPERM));
warnc(EPERM, "-u option");
quickexit(1);
}
rusername = optarg;

View File

@ -1,4 +1,4 @@
/* $OpenBSD: look.c,v 1.14 2013/11/26 13:19:07 deraadt Exp $ */
/* $OpenBSD: look.c,v 1.15 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: look.c,v 1.7 1995/08/31 22:41:02 jtc Exp $ */
/*-
@ -127,7 +127,7 @@ main(int argc, char *argv[])
if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
err(2, "%s", file);
if (sb.st_size > SIZE_T_MAX)
errx(2, "%s: %s", file, strerror(EFBIG));
errc(2, EFBIG, "%s", file);
if ((front = mmap(NULL,
(size_t)sb.st_size, PROT_READ, MAP_PRIVATE, fd, (off_t)0)) == MAP_FAILED)
err(2, "%s", file);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: lex.c,v 1.36 2014/01/17 18:42:30 okan Exp $ */
/* $OpenBSD: lex.c,v 1.37 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: lex.c,v 1.10 1997/05/17 19:55:13 pk Exp $ */
/*
@ -81,8 +81,7 @@ setfile(char *name)
switch (stb.st_mode & S_IFMT) {
case S_IFDIR:
(void)Fclose(ibuf);
errno = EISDIR;
warn("%s", name);
warnc(EISDIR, "%s", name);
return(-1);
case S_IFREG:
@ -90,8 +89,7 @@ setfile(char *name)
default:
(void)Fclose(ibuf);
errno = EINVAL;
warn("%s", name);
warnc(EINVAL, "%s", name);
return(-1);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: netcat.c,v 1.118 2014/03/12 10:19:40 jca Exp $ */
/* $OpenBSD: netcat.c,v 1.119 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 2001 Eric Jackson <ericj@monkey.org>
*
@ -608,7 +608,7 @@ remote_connect(const char *host, const char *port, struct addrinfo hints)
if (bind(s, (struct sockaddr *)ares->ai_addr,
ares->ai_addrlen) < 0)
errx(1, "bind failed: %s", strerror(errno));
err(1, "bind failed");
freeaddrinfo(ares);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: nl.c,v 1.2 2013/11/15 22:20:04 millert Exp $ */
/* $OpenBSD: nl.c,v 1.3 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: nl.c,v 1.11 2011/08/16 12:00:46 christos Exp $ */
/*-
@ -130,18 +130,14 @@ main(int argc, char *argv[])
break;
case 'd':
clen = mbrlen(optarg, MB_CUR_MAX, NULL);
if (clen == (size_t)-1 || clen == (size_t)-2) {
errno = EILSEQ;
err(EXIT_FAILURE, NULL);
}
if (clen == (size_t)-1 || clen == (size_t)-2)
errc(EXIT_FAILURE, EILSEQ, NULL);
if (clen != 0) {
memcpy(delim1, optarg, delim1len = clen);
clen = mbrlen(optarg + delim1len,
MB_CUR_MAX, NULL);
if (clen == (size_t)-1 || clen == (size_t)-2) {
errno = EILSEQ;
err(EXIT_FAILURE, NULL);
}
if (clen == (size_t)-1 || clen == (size_t)-2)
errc(EXIT_FAILURE, EILSEQ, NULL);
if (clen != 0) {
memcpy(delim2, optarg + delim1len,
delim2len = clen);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: mkpath.c,v 1.3 2013/11/12 13:51:42 deraadt Exp $ */
/* $OpenBSD: mkpath.c,v 1.4 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1983, 1992, 1993
* The Regents of the University of California. All rights reserved.
@ -65,7 +65,7 @@ mkpath(char *path)
return (-1);
}
} else if (!S_ISDIR(sb.st_mode)) {
warnx("%s: %s", path, strerror(ENOTDIR));
warnc(ENOTDIR, "%s", path);
return (-1);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: printf.c,v 1.20 2014/04/18 11:35:51 guenther Exp $ */
/* $OpenBSD: printf.c,v 1.21 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1989 The Regents of the University of California.
@ -489,7 +489,7 @@ check_conversion(const char *s, const char *ep)
warnx ("%s: not completely converted", s);
rval = 1;
} else if (errno == ERANGE) {
warnx ("%s: %s", s, strerror(ERANGE));
warnc(ERANGE, "%s", s);
rval = 1;
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: skeyinit.c,v 1.54 2014/04/23 18:24:23 ajacoutot Exp $ */
/* $OpenBSD: skeyinit.c,v 1.55 2014/05/20 01:25:23 guenther Exp $ */
/* OpenBSD S/Key (skeyinit.c)
*
@ -220,10 +220,9 @@ main(int argc, char **argv)
if (rmkey) {
if (snprintf(filename, sizeof(filename),
"%s/%s", _PATH_SKEYDIR, pp->pw_name)
>= sizeof(filename)) {
errno = ENAMETOOLONG;
err(1, "Cannot remove S/Key entry");
}
>= sizeof(filename))
errc(1, ENAMETOOLONG,
"Cannot remove S/Key entry");
if (unlink(filename) != 0)
err(1, "Cannot remove S/Key entry");
printf("S/Key entry for %s removed.\n",
@ -275,10 +274,9 @@ main(int argc, char **argv)
(void)printf("[Adding %s with %s]\n", pp->pw_name,
ht ? ht : skey_get_algorithm());
if (snprintf(filename, sizeof(filename), "%s/%s",
_PATH_SKEYDIR, pp->pw_name) >= sizeof(filename)) {
errno = ENAMETOOLONG;
err(1, "Cannot create S/Key entry");
}
_PATH_SKEYDIR, pp->pw_name) >= sizeof(filename))
errc(1, ENAMETOOLONG,
"Cannot create S/Key entry");
if ((l = open(filename,
O_RDWR | O_NONBLOCK | O_CREAT | O_TRUNC |O_NOFOLLOW,
S_IRUSR | S_IWUSR)) == -1 ||
@ -532,8 +530,7 @@ convert_db(void)
/* Now write the new-style record. */
if (snprintf(filename, sizeof(filename), "%s/%s", _PATH_SKEYDIR,
logname) >= sizeof(filename)) {
errno = ENAMETOOLONG;
warn("%s", logname);
warnc(ENAMETOOLONG, "%s", logname);
continue;
}
fd = open(filename, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: spellprog.c,v 1.7 2013/11/28 18:24:55 deraadt Exp $ */
/* $OpenBSD: spellprog.c,v 1.8 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1991, 1993
@ -285,7 +285,7 @@ main(int argc, char **argv)
if (wlists[i].fd == -1 || fstat(wlists[i].fd, &sb) != 0)
err(1, "%s", argv[i]);
if (sb.st_size > SIZE_T_MAX)
errx(1, "%s: %s", argv[i], strerror(EFBIG));
errc(1, EFBIG, "%s", argv[i]);
wlists[i].front = mmap(NULL, (size_t)sb.st_size, PROT_READ,
MAP_PRIVATE, wlists[i].fd, (off_t)0);
if (wlists[i].front == MAP_FAILED)

View File

@ -1,4 +1,4 @@
/* $OpenBSD: uudecode.c,v 1.18 2012/03/04 04:05:15 fgsch Exp $ */
/* $OpenBSD: uudecode.c,v 1.19 2014/05/20 01:25:23 guenther Exp $ */
/* $FreeBSD: uudecode.c,v 1.49 2003/05/03 19:44:46 obrien Exp $ */
/*-
@ -260,8 +260,7 @@ decode2(void)
flags = O_WRONLY|O_CREAT|O_EXCL|O_NOFOLLOW;
if (lstat(outfile, &st) == 0) {
if (iflag) {
errno = EEXIST;
warn("%s: %s", infile, outfile);
warnc(EEXIST, "%s: %s", infile, outfile);
return (0);
}
switch (st.st_mode & S_IFMT) {
@ -273,8 +272,7 @@ decode2(void)
warn("%s: unlink %s", infile, outfile);
return (1);
case S_IFDIR:
errno = EISDIR;
warn("%s: %s", infile, outfile);
warnc(EISDIR, "%s: %s", infile, outfile);
return (1);
default:
if (oflag) {
@ -282,8 +280,7 @@ decode2(void)
flags &= ~(O_EXCL|O_NOFOLLOW);
break;
}
errno = EEXIST;
warn("%s: %s", infile, outfile);
warnc(EEXIST, "%s: %s", infile, outfile);
return (1);
}
} else if (errno != ENOENT) {

View File

@ -1,4 +1,4 @@
/* $OpenBSD: which.c,v 1.18 2013/04/10 02:57:20 guenther Exp $ */
/* $OpenBSD: which.c,v 1.19 2014/05/20 01:25:23 guenther Exp $ */
/*
* Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
@ -125,7 +125,7 @@ findprog(char *prog, char *path, int progmode, int allmatches)
p[--plen] = '\0'; /* strip trailing '/' */
if (plen + 1 + proglen >= sizeof(filename)) {
warnx("%s/%s: %s", p, prog, strerror(ENAMETOOLONG));
warnc(ENAMETOOLONG, "%s/%s", p, prog);
free(path);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: xinstall.c,v 1.56 2013/11/27 13:32:02 okan Exp $ */
/* $OpenBSD: xinstall.c,v 1.57 2014/05/20 01:25:23 guenther Exp $ */
/* $NetBSD: xinstall.c,v 1.9 1995/12/20 10:25:17 jonathan Exp $ */
/*
@ -181,7 +181,7 @@ main(int argc, char *argv[])
if (stat(*argv, &from_sb))
err(EX_OSERR, "%s", *argv);
if (!S_ISREG(to_sb.st_mode))
errx(EX_OSERR, "%s: %s", to_name, strerror(EFTYPE));
errc(EX_OSERR, EFTYPE, "%s", to_name);
if (to_sb.st_dev == from_sb.st_dev &&
to_sb.st_ino == from_sb.st_ino)
errx(EX_USAGE, "%s and %s are the same file", *argv, to_name);
@ -211,7 +211,7 @@ install(char *from_name, char *to_name, u_long fset, u_int flags)
if (stat(from_name, &from_sb))
err(EX_OSERR, "%s", from_name);
if (!S_ISREG(from_sb.st_mode))
errx(EX_OSERR, "%s: %s", from_name, strerror(EFTYPE));
errc(EX_OSERR, EFTYPE, "%s", from_name);
/* Build the target path. */
if (flags & DIRECTORY) {
(void)snprintf(pathbuf, sizeof(pathbuf), "%s/%s",
@ -228,7 +228,7 @@ install(char *from_name, char *to_name, u_long fset, u_int flags)
/* Only compare against regular files. */
if (docompare && !S_ISREG(to_sb.st_mode)) {
docompare = 0;
warnx("%s: %s", to_name, strerror(EFTYPE));
warnc(EFTYPE, "%s", to_name);
}
} else if (docompare) {
/* File does not exist so silently ignore compare flag. */
@ -298,7 +298,7 @@ install(char *from_name, char *to_name, u_long fset, u_int flags)
if (fstat(temp_fd, &temp_sb)) {
serrno = errno;
(void)unlink(tempfile);
errx(EX_OSERR, "%s: %s", tempfile, strerror(serrno));
errc(EX_OSERR, serrno, "%s", tempfile);
}
if (compare(temp_fd, tempfile, (size_t)temp_sb.st_size, to_fd,
@ -425,7 +425,7 @@ copy(int from_fd, char *from_name, int to_fd, char *to_name, off_t size,
from_fd, (off_t)0)) == MAP_FAILED) {
serrno = errno;
(void)unlink(to_name);
errx(EX_OSERR, "%s: %s", from_name, strerror(serrno));
errc(EX_OSERR, serrno, "%s", from_name);
}
madvise(p, size, MADV_SEQUENTIAL);
siz = (size_t)size;
@ -467,7 +467,7 @@ copy(int from_fd, char *from_name, int to_fd, char *to_name, off_t size,
if (nr != 0) {
serrno = errno;
(void)unlink(to_name);
errx(EX_OSERR, "%s: %s", from_name, strerror(serrno));
errc(EX_OSERR, serrno, "%s", from_name);
}
}
}
@ -542,7 +542,7 @@ strip(char *to_name)
case -1:
serrno = errno;
(void)unlink(to_name);
errx(EX_TEMPFAIL, "forks: %s", strerror(serrno));
errc(EX_TEMPFAIL, serrno, "forks");
case 0:
execl(path_strip, "strip", "--", to_name, (char *)NULL);
warn("%s", path_strip);
@ -572,14 +572,13 @@ install_dir(char *path)
int mkdir_errno = errno;
if (stat(path, &sb)) {
/* Not there; use mkdir()s errno */
errno = mkdir_errno;
err(EX_OSERR, "%s", path);
errc(EX_OSERR, mkdir_errno, "%s",
path);
/* NOTREACHED */
}
if (!S_ISDIR(sb.st_mode)) {
/* Is there, but isn't a directory */
errno = ENOTDIR;
err(EX_OSERR, "%s", path);
errc(EX_OSERR, ENOTDIR, "%s", path);
/* NOTREACHED */
}
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: elf_hide.c,v 1.7 2013/11/12 19:48:40 deraadt Exp $ */
/* $OpenBSD: elf_hide.c,v 1.8 2014/05/20 01:25:24 guenther Exp $ */
/*
* Copyright (c) 1997 Dale Rahn.
@ -354,7 +354,7 @@ reorder_syms(Elf_Ehdr * ehdr, Elf_Shdr * symsect,
tmpsymtab = (Elf_Sym *) calloc(1, symtabsize);
symmap = (Symmap *) calloc(nsyms, sizeof(Symmap));
if (!tmpsymtab || !symmap)
errx(5, "calloc: %s", strerror(ENOMEM));
errc(5, ENOMEM, "calloc");
bcopy(symtab, tmpsymtab, symtabsize);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: nlist.c,v 1.44 2013/11/12 13:11:10 deraadt Exp $ */
/* $OpenBSD: nlist.c,v 1.45 2014/05/20 01:25:24 guenther Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -320,7 +320,7 @@ create_knlist(char *name, int fd, DB *db)
error = __elf_knlist(fd, db, ksyms);
if (fmterr != NULL)
warnx("%s: %s: %s", kfile, fmterr, strerror(EFTYPE));
warnc(EFTYPE, "%s: %s", kfile, fmterr);
return(error);
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: lpr.c,v 1.45 2013/11/24 21:32:32 deraadt Exp $ */
/* $OpenBSD: lpr.c,v 1.46 2014/05/20 01:25:24 guenther Exp $ */
/* $NetBSD: lpr.c,v 1.19 2000/10/11 20:23:52 is Exp $ */
/*
@ -665,7 +665,7 @@ mktemps(void)
struct stat stb;
if (snprintf(buf, sizeof(buf), "%s/.seq", SD) >= sizeof(buf))
errx(1, "%s/.seq: %s", SD, strerror(ENAMETOOLONG));
errc(1, ENAMETOOLONG, "%s/.seq", SD);
PRIV_START;
if ((fd = safe_open(buf, O_RDWR|O_CREAT|O_NOFOLLOW, 0661)) < 0)
err(1, "cannot open %s", buf);

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pcidump.c,v 1.35 2013/11/12 19:48:53 deraadt Exp $ */
/* $OpenBSD: pcidump.c,v 1.36 2014/05/20 01:25:24 guenther Exp $ */
/*
* Copyright (c) 2006, 2007 David Gwynne <loki@animata.net>
@ -184,7 +184,7 @@ main(int argc, char *argv[])
error = probe(bus, dev, func);
if (error != 0)
errx(1, "\"%s\": %s", argv[0], strerror(error));
errc(1, error, "\"%s\"", argv[0]);
} else {
printf("Domain %s:\n", pcidev);
scanpcidomain();

View File

@ -1,4 +1,4 @@
/* $OpenBSD: procmap.c,v 1.52 2014/02/13 21:17:13 tedu Exp $ */
/* $OpenBSD: procmap.c,v 1.53 2014/05/20 01:25:24 guenther Exp $ */
/* $NetBSD: pmap.c,v 1.1 2002/09/01 20:32:44 atatat Exp $ */
/*
@ -309,8 +309,7 @@ main(int argc, char *argv[])
kproc = kvm_getprocs(kd, KERN_PROC_PID, pid,
sizeof(struct kinfo_proc), &rc);
if (kproc == NULL || rc == 0) {
errno = ESRCH;
warn("%d", pid);
warnc(ESRCH, "%d", pid);
pid = -1;
continue;
}

View File

@ -1,4 +1,4 @@
/* $OpenBSD: pwd_mkdb.c,v 1.43 2010/01/08 13:29:08 oga Exp $ */
/* $OpenBSD: pwd_mkdb.c,v 1.44 2014/05/20 01:25:24 guenther Exp $ */
/*-
* Copyright (c) 1991, 1993, 1994
@ -75,6 +75,7 @@ static int hasyp; /* are we running YP? */
void cleanup(void);
void error(char *);
void errorc(int, char *);
void errorx(char *);
void cp(char *, char *, mode_t);
void mv(char *, char *);
@ -360,8 +361,7 @@ scan(FILE *fp, struct passwd *pw, int *flags)
*flags = 0;
if (!pw_scan(line, pw, flags)) {
warnx("at line #%d", lcnt);
fmt: errno = EFTYPE; /* XXX */
error(pname);
fmt: errorc(EFTYPE, pname);
}
return (1);
@ -383,16 +383,14 @@ cp(char *from, char *to, mode_t mode)
int sverrno = errno;
(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
errno = sverrno;
error(buf);
errorc(sverrno, buf);
}
}
if (rcount < 0) {
int sverrno = errno;
(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
errno = sverrno;
error(buf);
errorc(sverrno, buf);
}
close(to_fd);
close(from_fd);
@ -407,8 +405,7 @@ mv(char *from, char *to)
int sverrno = errno;
(void)snprintf(buf, sizeof(buf), "%s to %s", from, to);
errno = sverrno;
error(buf);
errorc(sverrno, buf);
}
}
@ -421,6 +418,15 @@ error(char *name)
exit(1);
}
void
errorc(int code, char *name)
{
warnc(code, "%s", name);
cleanup();
exit(1);
}
void
errorx(char *name)
{