Blame string/test-strerror-errno.c

Packit Service 5505df
/* BZ #24024 strerror and errno test.
Packit Service 5505df
Packit Service 5505df
   Copyright (C) 2019 Free Software Foundation, Inc.
Packit Service 5505df
   This file is part of the GNU C Library.
Packit Service 5505df
Packit Service 5505df
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 5505df
   modify it under the terms of the GNU Lesser General Public
Packit Service 5505df
   License as published by the Free Software Foundation; either
Packit Service 5505df
   version 2.1 of the License, or (at your option) any later version.
Packit Service 5505df
Packit Service 5505df
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 5505df
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 5505df
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 5505df
   Lesser General Public License for more details.
Packit Service 5505df
Packit Service 5505df
   You should have received a copy of the GNU Lesser General Public
Packit Service 5505df
   License along with the GNU C Library; if not, see
Packit Service 5505df
   <http://www.gnu.org/licenses/>.  */
Packit Service 5505df
Packit Service 5505df
#include <dlfcn.h>
Packit Service 5505df
#include <errno.h>
Packit Service 5505df
#include <string.h>
Packit Service 5505df
Packit Service 5505df
#include <support/check.h>
Packit Service 5505df
#include <support/support.h>
Packit Service 5505df
Packit Service 5505df
/* malloc is allowed to change errno to a value different than 0, even when
Packit Service 5505df
   there is no actual error.  This happens for example when the memory
Packit Service 5505df
   allocation through sbrk fails.  Simulate this by interposing our own
Packit Service 5505df
   malloc implementation which sets errno to ENOMEM and calls the original
Packit Service 5505df
   malloc.  */
Packit Service 5505df
void
Packit Service 5505df
*malloc (size_t size)
Packit Service 5505df
{
Packit Service 5505df
  static void *(*real_malloc) (size_t size);
Packit Service 5505df
Packit Service 5505df
  if (!real_malloc)
Packit Service 5505df
    real_malloc = dlsym (RTLD_NEXT, "malloc");
Packit Service 5505df
Packit Service 5505df
  errno = ENOMEM;
Packit Service 5505df
Packit Service 5505df
  return (*real_malloc) (size);
Packit Service 5505df
}
Packit Service 5505df
Packit Service 5505df
/* strerror must not change the value of errno.  Unfortunately due to GCC bug
Packit Service 5505df
   #88576, this happens when -fmath-errno is used.  This simple test checks
Packit Service 5505df
   that it doesn't happen.  */
Packit Service 5505df
static int
Packit Service 5505df
do_test (void)
Packit Service 5505df
{
Packit Service 5505df
  char *msg;
Packit Service 5505df
Packit Service 5505df
  errno = 0;
Packit Service 5505df
  msg = strerror (-3);
Packit Service 5505df
  (void) msg;
Packit Service 5505df
  TEST_COMPARE (errno, 0);
Packit Service 5505df
Packit Service 5505df
  return 0;
Packit Service 5505df
}
Packit Service 5505df
Packit Service 5505df
#include <support/test-driver.c>