1 /* Test of strerror_r() function.
2 Copyright (C) 2007-2011 Free Software Foundation, Inc.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22 #include "signature.h"
23 SIGNATURE_CHECK (strerror_r, int, (int, char *, size_t));
35 /* Test results with valid errnum and enough room. */
39 ASSERT (strerror_r (EACCES, buf, sizeof (buf)) == 0);
40 ASSERT (buf[0] != '\0');
45 ASSERT (strerror_r (ETIMEDOUT, buf, sizeof (buf)) == 0);
46 ASSERT (buf[0] != '\0');
51 ASSERT (strerror_r (EOVERFLOW, buf, sizeof (buf)) == 0);
52 ASSERT (buf[0] != '\0');
55 /* POSIX requires strerror (0) to succeed. Reject use of "Unknown
56 error", but allow "Success", "No error", or even Solaris' "Error
57 0" which are distinct patterns from true out-of-range strings.
58 http://austingroupbugs.net/view.php?id=382 */
61 ret = strerror_r (0, buf, sizeof (buf));
65 ASSERT (strstr (buf, "nknown") == NULL);
67 /* Test results with out-of-range errnum and enough room. */
71 ret = strerror_r (-3, buf, sizeof (buf));
72 ASSERT (ret == 0 || ret == EINVAL);
74 ASSERT (buf[0] != '^');
77 /* Test results with a too small buffer. */
79 ASSERT (strerror_r (EACCES, buf, sizeof (buf)) == 0);
81 size_t len = strlen (buf);
84 for (i = 0; i <= len; i++)
86 strcpy (buf, "BADFACE");
88 ret = strerror_r (EACCES, buf, i);
92 /* Truncated result. POSIX allows this, and it actually
93 happens on AIX 6.1 and Cygwin. */
94 ASSERT ((strcmp (buf, "BADFACE") == 0) == (i == 0));
99 ASSERT (ret == ERANGE);
100 /* buf is clobbered nevertheless, on FreeBSD and MacOS X. */
104 strcpy (buf, "BADFACE");
106 ret = strerror_r (EACCES, buf, len + 1);