[illumos-Developer] HEADS UP: new timegm() and strptime/strftime options

Garrett D'Amore garrett at damore.org
Sat Dec 4 17:58:30 PST 2010


I just integrated 

317 strptime needs %Z support

This provides a new function, timegm(), which works like mktime() but
uses UTC/GMT rather than the local timezone as the reference.  Its
prototype lives in <time.h>.

Note that timegm is not available when using standards conforming flags
to limit "namespace pollution".  Also, the symbol is versioned in libc
under ILLUMOS_1.0, using linker mapfile versioning.  Future additions in
ILLUMOS should use this style of version name to avoid collisions with
symbols introduced by Oracle (SUNW type names).

If you use this symbol in your programs, be aware that the resulting
binaries will probably not operate on Solaris or OpenSolaris.

This change also provides full support for %z in strptime(), and
introduces a new strftime/strptime format specifier -- %s.  This format
specifier gives the UNIX time in seconds (i.e. since Jan 1, 1970.)
Here's an example using the "date" command:

garrett at thinkpad{16}> date +%s
1291514108

As with timegm, this format is not available on Solaris, so if you use
it in programs be advised that they may not operate on Solaris or
OpenSolaris.

(Both of these features are present on Linux and the various BSD UNIX
systems, so this may help with portability.)

	- Garrett





More information about the Developer mailing list