1 /* Test of strerror_r() function.
2 Copyright (C) 2007-2010 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 /* Test results with out-of-range errnum and enough room. */
52 ret = strerror_r (0, buf, sizeof (buf));
53 ASSERT (ret == 0 || ret == EINVAL);
55 ASSERT (buf[0] != '^');
58 ret = strerror_r (-3, buf, sizeof (buf));
59 ASSERT (ret == 0 || ret == EINVAL);
61 ASSERT (buf[0] != '^');
63 /* Test results with a too small buffer. */
65 ASSERT (strerror_r (EACCES, buf, sizeof (buf)) == 0);
67 size_t len = strlen (buf);
70 for (i = 0; i <= len; i++)
72 strcpy (buf, "BADFACE");
73 ret = strerror_r (EACCES, buf, i);
76 /* Truncated result. POSIX allows this, and it actually
77 happens on AIX 6.1. */
78 ASSERT (strcmp (buf, "BADFACE") != 0);
83 ASSERT (ret == ERANGE);
84 /* buf is clobbered nevertheless, on FreeBSD and MacOS X. */
88 strcpy (buf, "BADFACE");
89 ret = strerror_r (EACCES, buf, len + 1);