rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit 32514265eae23c9196b09477c63ab26850ecbe6a
parent 55187d8e921d611b3fa9ff4a166125c44b7dd6d9
Author: tjg <tjg>
Date:   Wed, 13 Oct 1999 15:37:34 +0000

  Portability: use POSIX strerror() where it's available; fake it with
  sys_errlist[] where not.

Diffstat:
MChangeLog | 3+++
Mconfigure.ac | 2+-
Mproto.h | 9+++++++++
Mutils.c | 15++++++++-------
4 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -624,3 +624,6 @@ Changes since rc-1.5b2 rc_exit(). This bug is easily tickled on systems (like Linux) which allow you to open(2) but not read(2) directories: `. /tmp'. In all previous versions of rc, this caused the shell to exit. + + Portability: use POSIX strerror() where it's available; fake it with + sys_errlist[] where not. diff --git a/configure.ac b/configure.ac @@ -38,7 +38,7 @@ AC_TYPE_SIZE_T AC_TYPE_UID_T AC_CHECK_TYPE(ssize_t, long) -AC_CHECK_FUNCS(getgroups setpgrp setrlimit) +AC_CHECK_FUNCS(getgroups setpgrp setrlimit strerror) RC_FUNC_GETGROUPS RC_FUNC_SIGSETJMP diff --git a/proto.h b/proto.h @@ -59,6 +59,15 @@ extern void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); #endif /* STDC_HEADERS */ +#if HAVE_STRERROR +/* Smells like POSIX. */ +#else +/* Assume BSD-style sys_errlist[]. */ +extern int sys_nerr; +extern char *sys_errlist[]; +#define strerror(x) ((0 <= (x)) && (errno < (x)) ? sys_errlist[x] : (char *)0) +#endif + #if HAVE_UNISTD_H #include <unistd.h> #endif diff --git a/utils.c b/utils.c @@ -19,14 +19,15 @@ extern void pr_error(char *s, int offset) { /* our perror */ extern void uerror(char *s) { - extern int sys_nerr; - extern char *sys_errlist[]; - if (errno > sys_nerr) - return; - if (s != NULL) - fprint(2, "%s: %s\n", s, sys_errlist[errno]); + char *err; + + err = strerror(errno); + if (!err) err = "unknown error"; + + if (s) + fprint(2, "%s: %s\n", s, err); else - fprint(2, "%s\n", sys_errlist[errno]); + fprint(2, "%s\n", err); } /* Die horribly. This should never get called. Please let me know if it does. */