bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strerror and perror / strerror_r error messages differ


From: Bruno Haible
Subject: strerror and perror / strerror_r error messages differ
Date: Sat, 03 Sep 2022 00:21:31 +0200

Hi,

POSIX [1] requires that the error messages from perror and strerror for
the same error number are the same:
  "The contents of the error message strings shall be the same as those
   returned by strerror() with argument errno."

On glibc/Linux this is fulfilled. On glibc/Hurd this is not true for negative
error numbers.

How to reproduce:
=================================== foo.c ===================================
#define _GNU_SOURCE 1
#include <errno.h>
#include <stdio.h>
#include <string.h>

int main ()
{
  int errnum = -3;

  printf ("strerror -> %s\n", strerror (errnum));

  char buf[80];
  strerror_r (errnum, buf, sizeof buf);
  printf ("strerror_r -> %s\n", buf);

  errno = errnum;
  perror("perror");
}
=============================================================================
$ gcc -Wall foo.c
$ ./a.out
strerror -> Error in unknown error system: FFFFFFFD
strerror_r -> Error in unknown error system: : -3
perror: Error in unknown error system: : -3

Note the two differences:
  - decimal vs. hexadecimal output,
  - an extra ": " in the decimal case.

Seen on Debian GNU/Hurd, with glibc 2.34.

Bruno

[1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/perror.html






reply via email to

[Prev in Thread] Current Thread [Next in Thread]