summaryrefslogtreecommitdiffstats
path: root/newlib/libc/string/strerror_r.c
diff options
context:
space:
mode:
Diffstat (limited to 'newlib/libc/string/strerror_r.c')
-rw-r--r--newlib/libc/string/strerror_r.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/newlib/libc/string/strerror_r.c b/newlib/libc/string/strerror_r.c
new file mode 100644
index 000000000..956a1f485
--- /dev/null
+++ b/newlib/libc/string/strerror_r.c
@@ -0,0 +1,53 @@
+/*
+FUNCTION
+ <<strerror_r>>---convert error number to string and copy to buffer
+
+INDEX
+ strerror_r
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ char *strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>);
+
+TRAD_SYNOPSIS
+ #include <string.h>
+ char *strerror_r(<[errnum]>, <[buffer]>, <[n]>)
+ int <[errnum]>;
+ char *<[buffer]>;
+ size_t <[n]>;
+
+DESCRIPTION
+<<strerror_r>> converts the error number <[errnum]> into a
+string and copies the result into the supplied <[buffer]> for
+a length up to <[n]>, including the NUL terminator. The value of
+<[errnum]> is usually a copy of <<errno>>. If <<errnum>> is not a known
+error number, the result is the empty string.
+
+See <<strerror>> for how strings are mapped to <<errnum>>.
+
+RETURNS
+This function returns a pointer to a string. Your application must
+not modify that string.
+
+PORTABILITY
+<<strerror_r>> is a gnu extension.
+
+<<strerror_r>> requires no supporting OS subroutines.
+
+*/
+
+#undef __STRICT_ANSI__
+#include <errno.h>
+#include <string.h>
+
+char *
+_DEFUN (strerror_r, (errnum, buffer, n),
+ int errnum _AND
+ char *buffer _AND
+ size_t n)
+{
+ char *error;
+ error = strerror (errnum);
+
+ return strncpy (buffer, (const char *)error, n);
+}