Blame gnulib-tests/perror.c

Packit Service fdd496
/* Print a message describing error code.
Packit Service fdd496
   Copyright (C) 2008-2017 Free Software Foundation, Inc.
Packit Service fdd496
   Written by Bruno Haible and Simon Josefsson.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
/* Specification.  */
Packit Service fdd496
#include <stdio.h>
Packit Service fdd496
Packit Service fdd496
#include <errno.h>
Packit Service fdd496
#include <stdlib.h>
Packit Service fdd496
#include <string.h>
Packit Service fdd496
Packit Service fdd496
#include "strerror-override.h"
Packit Service fdd496
Packit Service fdd496
/* Use the system functions, not the gnulib overrides in this file.  */
Packit Service fdd496
#undef fprintf
Packit Service fdd496
Packit Service fdd496
void
Packit Service fdd496
perror (const char *string)
Packit Service fdd496
{
Packit Service fdd496
  char stackbuf[STACKBUF_LEN];
Packit Service fdd496
  int ret;
Packit Service fdd496
Packit Service fdd496
  /* Our implementation guarantees that this will be a non-empty
Packit Service fdd496
     string, even if it returns EINVAL; and stackbuf should be sized
Packit Service fdd496
     large enough to avoid ERANGE.  */
Packit Service fdd496
  ret = strerror_r (errno, stackbuf, sizeof stackbuf);
Packit Service fdd496
  if (ret == ERANGE)
Packit Service fdd496
    abort ();
Packit Service fdd496
Packit Service fdd496
  if (string != NULL && *string != '\0')
Packit Service fdd496
    fprintf (stderr, "%s: %s\n", string, stackbuf);
Packit Service fdd496
  else
Packit Service fdd496
    fprintf (stderr, "%s\n", stackbuf);
Packit Service fdd496
}