Bug 27610

Summary: snprintf() is undefined by _XOPEN_SOURCE=500 on BSDs, making poppler 0.12.4 fail to compile.
Product: poppler Reporter: Javier Villavicencio <the_paya>
Component: generalAssignee: poppler-bugs <poppler-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: x86 (IA32)   
OS: FreeBSD   
Whiteboard:
i915 platform: i915 features:

Description Javier Villavicencio 2010-04-12 20:45:54 UTC
CMake config (autotools too I think, just did a quick grep) is adding the define -D_XOPEN_SOURCE=500 which (at that version, 500) correctly leaves snprintf() undefined, according to the spec.
Given that function is being used in poppler/Catalog.cc, the proper define should be -D_XOPEN_SOURCE=600.

Perhaps unrelated to the summary, but also causing compile to fail here, strcasecmp() is being used in 2 places, poppler/GlobalParams.cc and test/perf-test.cc, this is defined on <strings.h> (on both BSD and Linux), which isn't included in the source files (they only have <string.h>, which seems to be enough for Linux).
Comment 1 Albert Astals Cid 2010-04-13 14:03:35 UTC
Can you point to the spec that says that snprintf shall be undefined when -D_XOPEN_SOURCE=500

I added the strings.h include for strcasecmp
Comment 2 Javier Villavicencio 2010-04-13 15:32:38 UTC
(In reply to comment #1)
> Can you point to the spec that says that snprintf shall be undefined when
> -D_XOPEN_SOURCE=500
> 
> I added the strings.h include for strcasecmp

Thanks.
About the specs, my apologies I should have included the references while I had them at hand, and "correctly undefined" sounds a bit blunt. Silly of me.

To correct myself on the subject, what I found while investigating this is that, since snprintf behavior was redefined between standards [1], the headers only define it (and a few others) when the standard the library supports is in use or requested, which is (usually) SUSv2 or ISO C99 or POSIX98 (not 100% sure on the posix one).

While _XOPEN_SOURCE=500 goes back to pre-1998 (speaking of standards) and that (older) implementation of snprintf is not supported on BSD (neither on glibc I think), it's then left undefined (a suggestive way for programs to provide the implementation they want, if I may add).
Linux glibc also behaves in a similar way: one of the requisites for defining snprintf in <stdio.h> is "_XOPEN_SOURCE > 500" (coming from <features.h>). But it's then ||or'ed to another define that comes from _BSD_SOURCE (it sets __USE_BSD), which is a bliss for glibc in this case, given that -D_BSD_SOURCE is also defined by poppler here.

[1] http://www.opengroup.org/onlinepubs/009695399/functions/snprintf.html (at the bottom)
Comment 3 Albert Astals Cid 2010-04-14 11:27:18 UTC
Changed to 600, anyway, that option is only set if you use a non standard compile option that you should not be using unless you know what you are doing.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.