mirror of
https://git.savannah.gnu.org/git/gnulib.git
synced 2026-10-24 00:48:56 +03:00
Done through sed -e 's/SIZEOF \([(][^()]*[)]\)/countof \1/g' * lib/boot-time.c: Include <stdcountof.h>. * lib/readutmp.c: Include <stdcountof.h>. * lib/boot-time-aux.h (get_linux_boot_time_fallback, get_openbsd_boot_time, get_windows_boot_time): Use countof. * lib/duplocale.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (duplocale): Use countof instead. * lib/fatal-signal.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (num_fatal_signals, actions_allocated): Use countof instead. * lib/iconv_open.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (rpl_iconv_open): Use countof instead. * lib/term-style-control.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (num_job_control_signals): Use countof instead. * lib/uniconv/u16-conv-to-enc.c: Include <stdcountof.h>. (SIZEOF): Remove macro. * lib/uniconv/u32-conv-to-enc.c: Include <stdcountof.h>. (SIZEOF): Remove macro. * lib/uniconv/u-conv-to-enc.h (FUNC): Use countof instead. * lib/uniconv/u16-strconv-to-enc.c: Include <stdcountof.h>. (SIZEOF): Remove macro. * lib/uniconv/u32-strconv-to-enc.c: Include <stdcountof.h>. (SIZEOF): Remove macro. * lib/uniconv/u-strconv-to-enc.h (FUNC): Use countof instead. * lib/uniname/uniname.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (unicode_name_word, unicode_name_word_lookup, unicode_code_to_index, unicode_index_to_code, unicode_character_name, unicode_name_character): Use countof instead. * lib/uniwidth/width.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (uc_width): Use countof instead. * lib/wait-process.c: Include <stdcountof.h>. (SIZEOF): Remove macro. (slaves_allocated): Use countof instead. * lib/gen-uni-tables.c (countof): Renamed from SIZEOF. * modules/boot-time (Depends-on): Add stdcountof-h. * modules/readutmp (Depends-on): Likewise. * modules/duplocale (Depends-on): Likewise. * modules/fatal-signal (Depends-on): Likewise. * modules/iconv_open (Depends-on): Likewise. * modules/term-style-control (Depends-on): Likewise. * modules/uniconv/u16-conv-to-enc (Depends-on): Likewise. * modules/uniconv/u32-conv-to-enc (Depends-on): Likewise. * modules/uniconv/u16-strconv-to-enc (Depends-on): Likewise. * modules/uniconv/u32-strconv-to-enc (Depends-on): Likewise. * modules/uniname/uniname (Depends-on): Likewise. * modules/uniwidth/width (Depends-on): Likewise. * modules/wait-process (Depends-on): Likewise. * tests/macros.h (SIZEOF): Remove macro. * tests/**/*.[hc]: Use countof instead of SIZEOF. Include <stdcountof.h> as needed. * modules/**/*-tests (Depends-on): Add stdcountof-h if needed.
139 lines
3.5 KiB
C
139 lines
3.5 KiB
C
/* Test of perror() function.
|
|
Copyright (C) 2011-2026 Free Software Foundation, Inc.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3, or (at your option)
|
|
any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, see <https://www.gnu.org/licenses/>. */
|
|
|
|
#include <config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
#include <stdcountof.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
|
|
/* Tell GCC not to warn about myerr being leaked. */
|
|
#if _GL_GNUC_PREREQ (13, 0)
|
|
# pragma GCC diagnostic ignored "-Wanalyzer-fd-leak"
|
|
#endif
|
|
|
|
/* This test intentionally parses stderr. So, we arrange to have fd 10
|
|
(outside the range of interesting fd's during the test) set up to
|
|
duplicate the original stderr. */
|
|
#define BACKUP_STDERR_FILENO 10
|
|
#define ASSERT_STREAM myerr
|
|
#include "macros.h"
|
|
|
|
static FILE *myerr;
|
|
|
|
#define BASE "test-perror2"
|
|
|
|
int
|
|
main (void)
|
|
{
|
|
/* We change fd 2 later, so save it in fd 10. */
|
|
if (dup2 (STDERR_FILENO, BACKUP_STDERR_FILENO) != BACKUP_STDERR_FILENO
|
|
|| (myerr = fdopen (BACKUP_STDERR_FILENO, "w")) == NULL)
|
|
return 2;
|
|
|
|
ASSERT (freopen (BASE ".tmp", "w+", stderr) == stderr);
|
|
|
|
/* Test that perror does not clobber strerror buffer. */
|
|
{
|
|
const char *msg1;
|
|
const char *msg2;
|
|
const char *msg3;
|
|
const char *msg4;
|
|
char *str1;
|
|
char *str2;
|
|
char *str3;
|
|
char *str4;
|
|
|
|
msg1 = strerror (ENOENT);
|
|
ASSERT (msg1);
|
|
str1 = strdup (msg1);
|
|
ASSERT (str1);
|
|
|
|
msg2 = strerror (ERANGE);
|
|
ASSERT (msg2);
|
|
str2 = strdup (msg2);
|
|
ASSERT (str2);
|
|
|
|
msg3 = strerror (-4);
|
|
ASSERT (msg3);
|
|
str3 = strdup (msg3);
|
|
ASSERT (str3);
|
|
|
|
msg4 = strerror (1729576);
|
|
ASSERT (msg4);
|
|
str4 = strdup (msg4);
|
|
ASSERT (str4);
|
|
|
|
errno = EACCES;
|
|
perror ("");
|
|
errno = -5;
|
|
perror ("");
|
|
ASSERT (!ferror (stderr));
|
|
ASSERT (streq (msg4, str4));
|
|
|
|
free (str1);
|
|
free (str2);
|
|
free (str3);
|
|
free (str4);
|
|
}
|
|
|
|
/* Test that perror uses the same message as strerror. */
|
|
{
|
|
int errs[] = { EACCES, 0, -3, };
|
|
for (int i = 0; i < countof (errs); i++)
|
|
{
|
|
char buf[256];
|
|
const char *err = strerror (errs[i]);
|
|
|
|
ASSERT (err);
|
|
ASSERT (strlen (err) < sizeof buf);
|
|
rewind (stderr);
|
|
ASSERT (ftruncate (fileno (stderr), 0) == 0);
|
|
errno = errs[i];
|
|
perror (NULL);
|
|
ASSERT (!ferror (stderr));
|
|
rewind (stderr);
|
|
ASSERT (fgets (buf, sizeof buf, stderr) == buf);
|
|
ASSERT (strstr (buf, err));
|
|
}
|
|
}
|
|
|
|
/* Test that perror reports write failure. */
|
|
{
|
|
ASSERT (freopen (BASE ".tmp", "r", stderr) == stderr);
|
|
ASSERT (setvbuf (stderr, NULL, _IONBF, BUFSIZ) == 0);
|
|
errno = -1;
|
|
ASSERT (!ferror (stderr));
|
|
perror (NULL);
|
|
#if 0
|
|
/* Commented out until cygwin behaves:
|
|
https://sourceware.org/ml/newlib/2011/msg00228.html */
|
|
ASSERT (errno > 0);
|
|
/* Commented out until glibc behaves:
|
|
https://sourceware.org/PR12792 */
|
|
ASSERT (ferror (stderr));
|
|
#endif
|
|
}
|
|
|
|
ASSERT (fclose (stderr) == 0);
|
|
ASSERT (remove (BASE ".tmp") == 0);
|
|
|
|
return test_exit_status;
|
|
}
|