Page MenuHomeWildfire Games

Compilation fix for non-glibc Linux systems
Needs ReviewPublic

Authored by parazyd on Jun 16 2017, 5:07 PM.

Details

Reviewers
None
Group Reviewers
Restricted Owners Package(Owns No Changed Paths)
Summary

On Gentoo I am unable to compile 0ad when I am using musl-libc.

It fails with the following error:

../../../source/third_party/cppformat/format.cpp: In function 'int fmt::internal::safe_strerror(int, char*&, std::size_t)':
../../../source/third_party/cppformat/format.cpp:435:29: error: invalid conversion from 'int' to 'char*' [-fpermissive]
   char *message = strerror_r(error_code, buffer, buffer_size);

strerror(3) says that "char *strerror_r()" is specific to GNU, and "int strerror_r()" should be XSI-compliant, which I believe is also the case with musl-libc.

This patch will change the strerror_r() call to strerror() in order to keep it being a char pointer, and still allow compilation on non-glibc (in this case musl-libc) systems.

Excerpt from the manpage:

strerror_r()
    The  strerror_r()  function  is  similar to strerror(), but is thread safe.  This function is available in two
    versions: an XSI-compliant version specified in POSIX.1-2001 (available since glibc 2.3.4, but not  POSIX-com‐
    pliant  until  glibc 2.13), and a GNU-specific version (available since glibc 2.0).  The XSI-compliant version
    is provided with the feature test macros settings shown in the SYNOPSIS; otherwise the GNU-specific version is
    provided.  If no feature test macros are explicitly defined, then (since glibc 2.4) _POSIX_C_SOURCE is defined
    by default with the value 200112L, so that the XSI-compliant version of strerror_r() is provided by default.

    The XSI-compliant strerror_r() is preferred for portable applications.  It returns the  error  string  in  the
    user-supplied buffer buf of length buflen.

    The  GNU-specific strerror_r() returns a pointer to a string containing the error message.  This may be either
    a pointer to a string that the function stores in buf, or a pointer to  some  (immutable)  static  string  (in
    which  case buf is unused).  If the function stores a string in buf, then at most buflen bytes are stored (the
    string may be truncated if buflen is too small and errnum is unknown).  The string always includes a terminat‐
    ing null byte ('\0').
Test Plan

Review and discussion.

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

parazyd created this revision.Jun 16 2017, 5:07 PM
parazyd updated this revision to Diff 2587.Jun 16 2017, 5:21 PM

Forgot a line.

  • (binaries/data/mods/public/gui/credits/texts/programming.json should have an entry)
  • (You mentioned that you have compiled with the alpha 21 version. Alpha 22 also has a new`strerror` and gai_strerror occurance in StunClient.cpp and might or might not need something if this diff is accepted. You can grab the most recent code with svn co http://svn.wildfiregames.com/public/ps/trunk/ 0ad).

gai_strerror is available in POSIX, so it should not raise an issue.

I guess, if the patch is accepted, I can be added to the credits by someone. I'm not much in the need of it though.

Stan added a reviewer: Restricted Owners Package.May 28 2019, 3:47 PM
Stan added a subscriber: Stan.

@parazyd Sorry for the very long answer, is it still needed ?