summaryrefslogtreecommitdiff
path: root/libiberty/xstrerror.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /libiberty/xstrerror.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'libiberty/xstrerror.c')
-rw-r--r--libiberty/xstrerror.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/libiberty/xstrerror.c b/libiberty/xstrerror.c
new file mode 100644
index 000000000..2ea2200e9
--- /dev/null
+++ b/libiberty/xstrerror.c
@@ -0,0 +1,79 @@
+/* xstrerror.c -- jacket routine for more robust strerror() usage.
+ Fri Jun 16 18:30:00 1995 Pat Rankin <rankin@eql.caltech.edu>
+ This code is in the public domain. */
+
+/*
+
+@deftypefn Replacement char* xstrerror (int @var{errnum})
+
+Behaves exactly like the standard @code{strerror} function, but
+will never return a @code{NULL} pointer.
+
+@end deftypefn
+
+*/
+
+#include <stdio.h>
+
+#include "config.h"
+#include "libiberty.h"
+
+#ifdef VMS
+# include <errno.h>
+# if !defined (__STRICT_ANSI__) && !defined (__HIDE_FORBIDDEN_NAMES)
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+extern char *strerror (int,...);
+# define DONT_DECLARE_STRERROR
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+# endif
+#endif /* VMS */
+
+
+#ifndef DONT_DECLARE_STRERROR
+# ifdef __cplusplus
+extern "C" {
+# endif /* __cplusplus */
+extern char *strerror (int);
+# ifdef __cplusplus
+}
+# endif /* __cplusplus */
+#endif
+
+/* If strerror returns NULL, we'll format the number into a static buffer. */
+
+#define ERRSTR_FMT "undocumented error #%d"
+static char xstrerror_buf[sizeof ERRSTR_FMT + 20];
+
+/* Like strerror, but result is never a null pointer. */
+
+char *
+xstrerror (int errnum)
+{
+ char *errstr;
+#ifdef VMS
+ char *(*vmslib_strerror) (int,...);
+
+ /* Override any possibly-conflicting declaration from system header. */
+ vmslib_strerror = (char *(*) (int,...)) strerror;
+ /* Second argument matters iff first is EVMSERR, but it's simpler to
+ pass it unconditionally. `vaxc$errno' is declared in <errno.h>
+ and maintained by the run-time library in parallel to `errno'.
+ We assume that `errnum' corresponds to the last value assigned to
+ errno by the run-time library, hence vaxc$errno will be relevant. */
+ errstr = (*vmslib_strerror) (errnum, vaxc$errno);
+#else
+ errstr = strerror (errnum);
+#endif
+
+ /* If `errnum' is out of range, result might be NULL. We'll fix that. */
+ if (!errstr)
+ {
+ sprintf (xstrerror_buf, ERRSTR_FMT, errnum);
+ errstr = xstrerror_buf;
+ }
+ return errstr;
+}