bug-hurd
[Top][All Lists]
Advanced

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

abseil port: strerror_r behaviour differs from Debian/Linux


From: Diego Nieto Cid
Subject: abseil port: strerror_r behaviour differs from Debian/Linux
Date: Sat, 25 Jan 2025 21:03:27 +0000

Hello,

Attempting to port abseil source package to the GNU/Hurd I found some
weird behaviour in the strerror_r function call when errnum is -1.

    #include <stdio.h>
    #include <string.h>
    
    int main(int argc, char **argv)
    {
      char buf[100] = {0};
      strerror_r(-1, buf, 100);
      printf("strerror_r: %s\n", buf);
      return 0;
    }

This is my simplified reproducer. When I run it on Debian GNU/Linux
it outputs the following string:

    strerror_r: Unknown error -1

However, when running in GNU/Hurd, the output is a bit different:

    strerror_r: Error in unknown error system: FFFFFFFF

That difference makes the abseil test suite to produce an error
in the following test[1]:

    TEST(StrErrorTest, InvalidErrorCode) {
      errno = ERANGE;
      EXPECT_THAT(absl::base_internal::StrError(-1),
                  AnyOf(Eq("No error information"), Eq("Unknown error -1")));
      EXPECT_THAT(errno, Eq(ERANGE));
    }


The POSIX specification says that an unknown error shall be indicated[2]:

    [CX] [Option Start] If the value of errnum is a valid error number, the
    message string shall indicate what error occurred; if the value of
    errnum is zero, the message string shall either be an empty string or
    indicate that no error occurred; otherwise, if these functions complete
    successfully, the message string shall indicate that an unknown error
    occurred. [Option End]

One could argue that the requirement is fullfilled, the message says
`unknown error` after all :-) But aligning to what GNU/Linux does would
help the porting to be easier.

What should we do here?

Regards,
Diego

--
[1] 
https://github.com/abseil/abseil-cpp/blob/master/absl/base/internal/strerror_test.cc#L41
[2] https://pubs.opengroup.org/onlinepubs/9799919799/functions/strerror.html



reply via email to

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