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. */
38 ASSERT (strerror_r (EACCES, buf, sizeof (buf)) == 0);
39 ASSERT (buf[0] != '\0');
42 ASSERT (strerror_r (ETIMEDOUT, buf, sizeof (buf)) == 0);
43 ASSERT (buf[0] != '\0');
46 ASSERT (strerror_r (EOVERFLOW, buf, sizeof (buf)) == 0);
47 ASSERT (buf[0] != '\0');
49 /* POSIX requires strerror (0) to succeed. Reject use of "Unknown
50 error", but allow "Success", "No error", or even Solaris' "Error
51 0" which are distinct patterns from true out-of-range strings.
52 http://austingroupbugs.net/view.php?id=382 */
54 ret = strerror_r (0, buf, sizeof (buf));
57 ASSERT (strstr (buf, "nknown") == NULL);
59 /* Test results with out-of-range errnum and enough room. */
62 ret = strerror_r (-3, buf, sizeof (buf));
63 ASSERT (ret == 0 || ret == EINVAL);
65 ASSERT (buf[0] != '^');
67 /* Test results with a too small buffer. */
69 ASSERT (strerror_r (EACCES, buf, sizeof (buf)) == 0);
71 size_t len = strlen (buf);
74 for (i = 0; i <= len; i++)
76 strcpy (buf, "BADFACE");
77 ret = strerror_r (EACCES, buf, i);
80 /* Truncated result. POSIX allows this, and it actually
81 happens on AIX 6.1 and Cygwin. */
82 ASSERT ((strcmp (buf, "BADFACE") == 0) == (i == 0));
87 ASSERT (ret == ERANGE);
88 /* buf is clobbered nevertheless, on FreeBSD and MacOS X. */
92 strcpy (buf, "BADFACE");
93 ret = strerror_r (EACCES, buf, len + 1);