After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 133344 - _POSIX_SOURCE causes compile problem in glib
_POSIX_SOURCE causes compile problem in glib
Status: RESOLVED OBSOLETE
Product: glib
Classification: Platform
Component: general
2.4.x
Other opensolaris
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2004-02-03 22:15 UTC by Brian Cameron
Modified: 2011-02-18 16:14 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch fixing the problem (276 bytes, patch)
2009-05-20 12:49 UTC, Thomas Klausner
none Details | Review

Description Brian Cameron 2004-02-03 22:15:05 UTC
On Solaris, trying to compile glib/giounix.c fails with the following error:

"/usr/include/sys/feature_tests.h", line 263: #error: "Compiler or options
invalid for pre-UNIX 03 X/Open applications       and pre-2001 POSIX
applications"

This problem goes away if the following line is removed.

#define _POSIX_SOURCE       /* for SSIZE_MAX */

This define doesn't seem to be needed in the giounix.c file, and the file
compiles fine on Solaris without it.  Can this be removed, or only included
on platforms that it is needed?

Thanks!
Comment 1 Manish Singh 2004-02-03 22:31:10 UTC
That was introduced to fix bug 128853. I suppose I could use
_GNU_SOURCE, but I'd hoped to address the issue on non-glibc platforms
too.

That error doesn't make much sense to me (and is not in the headers on
the Solaris 9 box I just looked at). Are you using gcc? what happens
if you compile with -ansi?
Comment 2 Brian Cameron 2004-02-03 23:32:36 UTC
I am using the Forte compiler on Solaris.  I am using a development
version of SolarisNext (the one that will be released after
Solaris 9).  So that is why the headers are different than what 
you see.   Forte supports these options:

-Xa             Compile assuming ANSI C conformance, allow K & R 
                extensions (default mode)
-Xc             Compile assuming strict ANSI C conformance
-Xs             Compile assuming (pre-ANSI) K & R C style code
-Xt             Compile assuming K & R conformance, allow ANSI C

I believe -Xa is the equilivant of -ansi for the gcc compiler.  I
tried using all of the above 4 options, and they all fail to compile.

If you want to #ifdef the logic so that it doesn't get used on 
Solaris, you could surround the #define with the following

#ifndef __SUNPRO_C
#endif

__SUNPRO_C is defined if you are compiling with Forte.
Comment 3 Manish Singh 2004-02-04 08:05:42 UTC
I'd rather try to figure out the right thing rather than do compiler
specific #ifdefs, especially since I don't know what will happen with gcc.

In limits.h (or wherever it is defined), what is the definition of
SSIZE_MAX guarded by?

Also, what is that #error guarded by?
Comment 4 Brian Cameron 2004-02-05 18:52:52 UTC
The error is guarded by (from /usr/include/sys/feature_tests.h):

/*
 * It is invalid to compile an XPG3, XPG4, XPG4v2, or XPG5 application
 * using c99.  The same is true for POSIX.1-1990, POSIX.2-1992, POSIX.1b,
 * and POSIX.1c applications. Likewise, it is invalid to compile an XPG6
 * or a POSIX.1-2001 application with anything other than a c99 or later
 * compiler.  Therefore, we force an error in both cases.
 */
#if defined(_STDC_C99) && (defined(__XOPEN_OR_POSIX) && !defined(_XPG6))
#error "Compiler or options invalid for pre-UNIX 03 X/Open applications \
    and pre-2001 POSIX applications"
#elif !defined(_STDC_C99) && \
    (defined(__XOPEN_OR_POSIX) && defined(_XPG6))
#error "Compiler or options invalid; UNIX 03 and POSIX.1-2001
applications \
    require the use of c99"
#endif

----

SSIZE_MAX is guarded by:

#if defined(__EXTENSIONS__) || !defined(_STRICT_STDC) || \
    defined(__XOPEN_OR_POSIX)

#define SSIZE_MAX   LONG_MAX    /* max value of an "ssize_t" */

[..]
#endif /* defined(__EXTENSIONS__) || !defined(_STRICT_STDC) ... */

---

Comment 5 Manish Singh 2004-02-10 08:09:19 UTC
Hmm, it looks like with Solaris 9 headers and gcc -ansi, #define
_POSIX_SOURCE is needed as well, so papering it over with _GNU_SOURCE
instead won't work. Probably the same thing will happen on Solaris 10
once gcc's fixincludes is changed to recognize _STRICT_STDC.

I'm really not sure what to do here. What do the Sun docs recommend
for an app that is both POSIX-1.1990 and POSIX.1-2001 compliant?
Comment 6 Owen Taylor 2004-03-14 05:03:58 UTC
It looks like we somehow need to get _XPG6 defined...
Comment 7 Matthias Clasen 2005-12-27 19:11:36 UTC
Brian, any progress on this front ? 
Is this still a problem ? 
Should we just close this bug ?
Comment 8 Brian Cameron 2006-03-16 03:15:43 UTC
Yes, we work around this problem with Forte by adding a patch that says this just before the #include "config.h" in giounix.c

+#ifdef _STDC_C99
+#undef _STDC_C99
+#endif
Comment 9 Thomas Klausner 2009-05-20 12:49:28 UTC
Created attachment 135013 [details] [review]
Patch fixing the problem

Defining _XOPEN_SOURCE to 600 fixes the compilation problem.
Comment 10 Matthias Clasen 2009-05-26 05:01:09 UTC
I wonder if it is not redundant to define both _POSIX_SOURCE and _XOPEN_SOURCE. 
Comment 11 Brian Cameron 2009-05-26 14:58:27 UTC
Doing some research on the patches that Sun applies, I see that we are not applying this patch anymore.  The patch was removed after glib was bumped to 2.12.4 in December 2006.  So I believe this issue was resolved via some other way.
I think this bug can just be closed.
Comment 12 Matthias Clasen 2009-05-26 15:03:05 UTC
thanks for the update