diff options
author | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-29 11:37:39 +0000 |
---|---|---|
committer | Tim J. Robbins <tjr@FreeBSD.org> | 2002-09-29 11:37:39 +0000 |
commit | 1c59560de9a5e6baf9bf9668e15a405c914772a0 (patch) | |
tree | b98ee1bc6b1544336b5f69e753b430c3bbbb9f63 /bin/sh | |
parent | f7f23e15f8a18961c4e0bdb97789f36731c1aed7 (diff) | |
download | src-1c59560de9a5e6baf9bf9668e15a405c914772a0.tar.gz src-1c59560de9a5e6baf9bf9668e15a405c914772a0.zip |
Convert the remaining callers of errmsg() to use strerror(), and remove
errmsg() and its table of error messages.
Notes
Notes:
svn path=/head/; revision=104132
Diffstat (limited to 'bin/sh')
-rw-r--r-- | bin/sh/error.c | 88 | ||||
-rw-r--r-- | bin/sh/error.h | 10 | ||||
-rw-r--r-- | bin/sh/exec.c | 4 | ||||
-rw-r--r-- | bin/sh/redir.c | 22 |
4 files changed, 13 insertions, 111 deletions
diff --git a/bin/sh/error.c b/bin/sh/error.c index 8c2c964a897e..7b00c8b7cc81 100644 --- a/bin/sh/error.c +++ b/bin/sh/error.c @@ -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; -} diff --git a/bin/sh/error.h b/bin/sh/error.h index 92ca8f8cce30..87442e035bc5 100644 --- a/bin/sh/error.h +++ b/bin/sh/error.h @@ -38,15 +38,6 @@ */ /* - * 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 * jump to when an exception occurs, and the global variable exception @@ -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); /* diff --git a/bin/sh/exec.c b/bin/sh/exec.c index 819089a9aeb0..d70d03e53c73 100644 --- a/bin/sh/exec.c +++ b/bin/sh/exec.c @@ -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 @@ loop: 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; diff --git a/bin/sh/redir.c b/bin/sh/redir.c index ed48f9fe260c..9f809d86caa3 100644 --- a/bin/sh/redir.c +++ b/bin/sh/redir.c @@ -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 @@ movefd: 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 @@ movefd: 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; |