Convert the remaining callers of errmsg() to use strerror(), and remove

errmsg() and its table of error messages.
This commit is contained in:
Tim J. Robbins 2002-09-29 11:37:39 +00:00
parent f7f23e15f8
commit 1c59560de9
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=104132
4 changed files with 13 additions and 111 deletions

View File

@ -180,91 +180,3 @@ exerror(int cond, const char *msg, ...)
exverror(cond, msg, ap);
va_end(ap);
}
/*
* Table of error messages.
*/
struct errname {
short errcode; /* error number */
short action; /* operation which encountered the error */
char *msg; /* text describing the error */
};
#define ALL (E_OPEN|E_CREAT|E_EXEC)
STATIC const struct errname errormsg[] = {
{ EINTR, ALL, "interrupted" },
{ EACCES, ALL, "permission denied" },
{ EIO, ALL, "I/O error" },
{ ENOENT, E_OPEN, "no such file" },
{ ENOENT, E_CREAT,"directory nonexistent" },
{ ENOENT, E_EXEC, "not found" },
{ ENOTDIR, E_OPEN, "no such file" },
{ ENOTDIR, E_CREAT,"directory nonexistent" },
{ ENOTDIR, E_EXEC, "not found" },
{ EISDIR, ALL, "is a directory" },
#ifdef notdef
{ EMFILE, ALL, "too many open files" },
#endif
{ ENFILE, ALL, "file table overflow" },
{ ENOSPC, ALL, "file system full" },
#ifdef EDQUOT
{ EDQUOT, ALL, "disk quota exceeded" },
#endif
#ifdef ENOSR
{ ENOSR, ALL, "no streams resources" },
#endif
{ ENXIO, ALL, "no such device or address" },
{ EROFS, ALL, "read-only file system" },
{ ETXTBSY, ALL, "text busy" },
{ ENOMEM, ALL, "not enough memory" },
#ifdef ENOLINK
{ ENOLINK, ALL, "remote access failed" },
#endif
#ifdef EMULTIHOP
{ EMULTIHOP, ALL, "remote access failed" },
#endif
#ifdef ECOMM
{ ECOMM, ALL, "remote access failed" },
#endif
#ifdef ESTALE
{ ESTALE, ALL, "remote access failed" },
#endif
#ifdef ETIMEDOUT
{ ETIMEDOUT, ALL, "remote access failed" },
#endif
#ifdef ELOOP
{ ELOOP, ALL, "symbolic link loop" },
#endif
{ E2BIG, E_EXEC, "argument list too long" },
#ifdef ELIBACC
{ ELIBACC, E_EXEC, "shared library missing" },
#endif
{ EEXIST, E_CREAT, "file exists" },
{ 0, 0, NULL },
};
/*
* Return a string describing an error. The returned string may be a
* pointer to a static buffer that will be overwritten on the next call.
* Action describes the operation that got the error.
*/
char *
errmsg(int e, int action)
{
struct errname const *ep;
static char buf[12];
for (ep = errormsg ; ep->errcode ; ep++) {
if (ep->errcode == e && (ep->action & action) != 0)
return ep->msg;
}
fmtstr(buf, sizeof buf, "error %d", e);
return buf;
}

View File

@ -37,15 +37,6 @@
* $FreeBSD$
*/
/*
* Types of operations (passed to the errmsg routine).
*/
#define E_OPEN 01 /* opening a file */
#define E_CREAT 02 /* creating a file */
#define E_EXEC 04 /* executing a program */
/*
* We enclose jmp_buf in a structure so that we can declare pointers to
* jump locations. The global variable handler contains the location to
@ -93,7 +84,6 @@ void exraise(int);
void onint(void);
void error(const char *, ...) __printf0like(1, 2);
void exerror(int, const char *, ...) __printf0like(2, 3);
char *errmsg(int, int);
/*

View File

@ -144,7 +144,7 @@ shellexec(char **argv, char **envp, char *path, int index)
exerrno = 2;
break;
}
exerror(EXEXEC, "%s: %s", argv[0], errmsg(e, E_EXEC));
exerror(EXEXEC, "%s: %s", argv[0], strerror(e));
}
@ -420,7 +420,7 @@ find_command(char *name, struct cmdentry *entry, int printerr, char *path)
if (cmdp)
delete_cmd_entry();
if (printerr)
outfmt(out2, "%s: %s\n", name, errmsg(e, E_EXEC));
outfmt(out2, "%s: %s\n", name, strerror(e));
entry->cmdtype = CMDUNKNOWN;
return;

View File

@ -179,7 +179,7 @@ openredirect(union node *redir, char memory[10])
case NFROM:
fname = redir->nfile.expfname;
if ((f = open(fname, O_RDONLY)) < 0)
error("cannot open %s: %s", fname, errmsg(errno, E_OPEN));
error("cannot open %s: %s", fname, strerror(errno));
movefd:
if (f != fd) {
close(fd);
@ -191,17 +191,17 @@ openredirect(union node *redir, char memory[10])
fname = redir->nfile.expfname;
#ifdef O_CREAT
if ((f = open(fname, O_RDWR|O_CREAT, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
#else
if ((f = open(fname, O_RDWR, 0666)) < 0) {
if (errno != ENOENT)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
else if ((f = creat(fname, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
else {
close(f);
if ((f = open(fname, O_RDWR)) < 0) {
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
remove(fname);
}
}
@ -212,29 +212,29 @@ openredirect(union node *redir, char memory[10])
fname = redir->nfile.expfname;
if (Cflag && stat(fname, &sb) != -1 && S_ISREG(sb.st_mode))
error("cannot create %s: %s", fname,
errmsg(EEXIST, E_CREAT));
strerror(EEXIST));
#ifdef O_CREAT
if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
#else
if ((f = creat(fname, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
#endif
goto movefd;
case NCLOBBER:
fname = redir->nfile.expfname;
if ((f = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
goto movefd;
case NAPPEND:
fname = redir->nfile.expfname;
#ifdef O_APPEND
if ((f = open(fname, O_WRONLY|O_CREAT|O_APPEND, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
#else
if ((f = open(fname, O_WRONLY)) < 0
&& (f = creat(fname, 0666)) < 0)
error("cannot create %s: %s", fname, errmsg(errno, E_CREAT));
error("cannot create %s: %s", fname, strerror(errno));
lseek(f, (off_t)0, 2);
#endif
goto movefd;