Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SunOS compatibility #107

Merged
merged 2 commits into from
Oct 14, 2024
Merged

SunOS compatibility #107

merged 2 commits into from
Oct 14, 2024

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Oct 14, 2024

The clar does not compile on SunOS because it does not support POSIX.1-2008. This PR makes things work on that platform.

We use a couple of functions not part of the ISO C standard, but instead
part of POSIX.1-2008. There are ancient platforms like SunOS that do not
support this standard, but which _do_ have the required functions hidden
away behind some other macros.

The feature test macros are a bit of a mess. The following functions are
what we require as non-standard extensions:

   strdup():
       _XOPEN_SOURCE >= 500
           || /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L
           || /* glibc <= 2.19: */ _BSD_SOURCE || _SVID_SOURCE

    snprintf(), vsnprintf():
        _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L;
        or cc -std=c99

    mkdtemp():
        _BSD_SOURCE
        || /* Since glibc 2.10: */
        (_POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700)

   lstat():
       /* Since glibc 2.20 */ _DEFAULT_SOURCE
           || _XOPEN_SOURCE >= 500
           || /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112L
           || /* glibc 2.19 and earlier */ _BSD_SOURCE

A few observations:

  - We cannot set _POSIX_C_SOURCE to 200809L because it will cause
    errors on platforms that do not support POSIX.1-2008.

  - We cannot easily set _XOPEN_SOURCE because on SunOS, we would have
    to set it conditionally depending on the current C standard used by
    the compiler.

What is common to all though is _BSD_SOURCE, even though it has been
deprecated in glibc 2.20. Quoting feature-test-macros(7):

  Since glibc 2.20, this macro is deprecated.  It now has the same
  effect as defining _DEFAULT_SOURCE, but generates a compile-time
  warning (unless _DEFAULT_SOURCE is also defined).  Use _DEFAULT_SOURCE
  instead.  To allow code that requires _BSD_SOURCE in glibc 2.19 and
  earlier and _DEFAULT_SOURCE in glibc 2.20 and later to compile without
  warnings, define both _BSD_SOURCE and _DEFAULT_SOURCE.

So even though _BSD_SOURCE is deprecated, we can set it in tandem with
_DEFAULT_SOURCE. Furthermore, _DEFAULT_SOURCE is defined to be roughly
equivalent to "-D_BSD_SOURCE -D_SVID_SOURCE -D_POSIX_C_SOURCE=200809",
which should thus enables all features required by us.

Replace our use of _POSIX_C_SOURCE with _BSD_SOURCE plus _DEFAULT_SOURCE
to make things work on SunOS.
We do not have mkdtemp(3p) available on SunOS, as it has only been added
with POSIX.1-2008. Use the same compatibility code that we use on HP
NonStop, which falls back to using mktemp(3) plus mkdir(3).
@pks-t pks-t self-assigned this Oct 14, 2024
@pks-t pks-t requested a review from ethomson October 14, 2024 06:33
@pks-t
Copy link
Member Author

pks-t commented Oct 14, 2024

@ethomson ethomson merged commit 0810a36 into clar-test:main Oct 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants