Arch Linux

Please read this before reporting a bug:
https://wiki.archlinux.org/title/Bug_reporting_guidelines

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!
Tasklist

FS#33256 - strptime man page #define is incorrect

Attached to Project: Arch Linux
Opened by Don Allen (donallen) - Monday, 31 December 2012, 15:25 GMT
Last edited by Gerardo Exequiel Pozzi (djgera) - Monday, 31 December 2012, 17:37 GMT
Task Type Bug Report
Category Packages: Extra
Status Closed
Assigned To No-one
Architecture x86_64
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

Description:
The strptime man page requires #define _XOPEN_SOURCE. When I do so and compile code that assigns the value of strptime to a char * value, I get a warning from gcc:

"assignment makes pointer from integer without a cast"

A check of /usr/include/types.h shows two function prototypes for strptime:

# ifdef __USE_XOPEN
/* Parse S according to FORMAT and store binary time information in TP.
The return value is a pointer to the first unparsed character in S. */
extern char *strptime (const char *__restrict __s,
const char *__restrict __fmt, struct tm *__tp)
__THROW;
# endif

and

# ifdef __USE_GNU
extern char *strptime_l (const char *__restrict __s,
const char *__restrict __fmt, struct tm *__tp,
__locale_t __loc) __THROW;
# endif

A full search of time.h for the string _XOPEN_SOURCE finds no matches. When I changed my header file to

#define __USE_XOPEN

the compilation warning went away.

Additional info:
* package version(s)
* config and/or log files etc.


Steps to reproduce:
This task depends upon

Closed by  Gerardo Exequiel Pozzi (djgera)
Monday, 31 December 2012, 17:37 GMT
Reason for closing:  Not a bug
Comment by Gerardo Exequiel Pozzi (djgera) - Monday, 31 December 2012, 16:41 GMT
I can not reproduce your issue. (_XOPEN_SOURCE defines __USE_XOPEN via features.h, included by time.h)
Comment by Daniel Micay (thestinger) - Monday, 31 December 2012, 17:04 GMT
The fact that there's no _POSIX_C_SOURCE prototype is a bug (since it is indeed part of POSIX), but I can't reproduce your issue either. This is the type of thing you should report upstream though - the packager can't do much about it.
Comment by Don Allen (donallen) - Monday, 31 December 2012, 17:10 GMT
Write this to test.c:

#include <stdlib.h>
#define _XOPEN_SOURCE
#include <time.h>

main()
{
struct tm tm;
char *foo = strptime("abcd", "xyz", &tm);
}

And do

gcc test.c

You will get the error. If you eliminate the #include <stdlib.h>, the error goes away. I have not attempted to diagnose the cause, as these header files are a pretty unbelievable rat's nest.
Comment by Daniel Micay (thestinger) - Monday, 31 December 2012, 17:11 GMT
You have to put the #define first. You should ideally be setting those with the compiler's -D flag because in a multi-file project they need to be consistent everywhere.
Comment by Gerardo Exequiel Pozzi (djgera) - Monday, 31 December 2012, 17:21 GMT
As Daniel says. (Because stdlib.h includes feature.h, then #define does not take any effect)
Comment by Don Allen (donallen) - Monday, 31 December 2012, 17:34 GMT
Yep -- I didn't read the feature_test_macros man page carefully enough. The necessity of defining the feature macros before any includes is in the note that is the second paragraph of the description.

Loading...