Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm compiling some code which requests POSIX 1003.1 1993 conformance via -D_POSIX_C_SOURCE=2.

The code includes the header <sys/time.h> and wants to call gettimeofday, but on NetBSD 5.1 there is a compiler warning about that function not being declared.

Looking into NetBSD's header, we see that the declaration of gettimeofday is wrapped with a test for _POSIX_C_SOURCE being at least 200112.

Was gettimeofday really only introduced to POSIX in 2001? That hardly seems right. In 1993, there was already clock_gettime with nanoseconds and different clock types, and getttimeofday is ancient 4.2 BSD stuff.

In the GNU C library's <sys/time.h>, gettimeofday is not wrapped by anything at all.

Which is is right: NetBSD header, or my code relying on _POSIX_C_SOURCE=2 to reveal the declaration of gettimeofday (and glibc, for providing it unconditionally)?

share|improve this question
up vote 1 down vote accepted

http://pubs.opengroup.org/onlinepubs/009604599/functions/gettimeofday.html does indeed say it was added in 2001.

share|improve this answer
I don't see where it says that. But aha, I didn't see this before. It mentions Issue 4, Version 2. That's 1997. – Kaz Apr 10 '12 at 22:39
Look here: pubs.opengroup.org/onlinepubs/007908799/xsh/gettimeofday.html It was already in the Single Unix Spec in 1997. – Kaz Apr 10 '12 at 22:39
Scroll down to the bottom, the "SEE ALSO" section references the POSIX version where it was added. (Not the current version, which for that particular reference is 2004.) – geekosaur Apr 10 '12 at 22:41
Also note that SUS and POSIX were not quite the same thing back then; SUS was The Open Group's original attempt at reconciling SVID and OSF/1 behavior, as distinct from ANSI's (POSIX) or X/Open's. They have since been merged into a single standard. – geekosaur Apr 10 '12 at 22:44
Looks like it may be a Unix95 thing that didn't in fact get into POSIX 1003 until 2001. – Kaz Apr 10 '12 at 22:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.