strftime.c: implement %N format specifier with extra semantics
commit1f19e74d21b4b511090794458ae4cd0094ed98f2
authorKyle J. McKay <mackyle@gmail.com>
Mon, 25 Dec 2017 16:00:41 +0000 (25 08:00 -0800)
committerKyle J. McKay <mackyle@gmail.com>
Mon, 25 Dec 2017 16:00:41 +0000 (25 08:00 -0800)
tree1e8e708bff5e3f8616b0a863d381ac555bc7b60e
parent59c0d315317cd78ba2c9c9f419d7387e4054437b
strftime.c: implement %N format specifier with extra semantics

The '%N' format specifier is implemented to insert the 9-digit
nanoseconds value (which will always be all zeros unless the current
time is used).

Since the gettimeofday() function only provides microseconds, the
last three digits of the %N value will always be zero anyway.

To assist with generating unique names, the "extra semantics" are
that whenever %N is used together with current time then a 1 ms
sleep will be performed before and after the call to the gettimeofday()
function.  This provides a guarantee to the caller (excluding the
possibility of any clock resets) that combining the pid with the
timestamp will produce a unique value that will not be generated
by any other process on the system either before or after the call.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
src/strftime.c