1 /* Test of perror() function.
2 Copyright (C) 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. */
26 /* This test intentionally parses stderr. So, we arrange to have fd 10
27 (outside the range of interesting fd's during the test) set up to
28 duplicate the original stderr. */
29 #define BACKUP_STDERR_FILENO 10
30 #define ASSERT_STREAM myerr
35 #define BASE "test-perror2"
42 /* We change fd 2 later, so save it in fd 10. */
43 if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
44 || (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
47 ASSERT (freopen (BASE ".tmp", "w+", stderr) == stderr);
49 /* Test that perror does not clobber strerror buffer. */
60 msg1 = strerror (ENOENT);
65 msg2 = strerror (ERANGE);
75 msg4 = strerror (1729576);
84 ASSERT (!ferror (stderr));
85 ASSERT (msg1 == msg2 || msg1 == msg4 || STREQ (msg1, str1));
86 ASSERT (msg2 == msg4 || STREQ (msg2, str2));
87 ASSERT (msg3 == msg4 || STREQ (msg3, str3));
88 ASSERT (STREQ (msg4, str4));
91 /* Test that perror reports write failure. */
93 ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);
94 ASSERT (setvbuf (stderr, NULL, _IOLBF, BUFSIZ) == 0);
96 ASSERT (!ferror (stderr));
100 /* Commented out until glibc behaves:
101 http://sourceware.org/bugzilla/show_bug.cgi?id=12792 */
102 ASSERT (ferror (stderr));
106 ASSERT (fclose (stderr) == 0);
107 ASSERT (remove (BASE ".tmp") == 0);