Index: lib/libc/stdtime/strftime.3 =================================================================== --- lib/libc/stdtime/strftime.3 +++ lib/libc/stdtime/strftime.3 @@ -32,7 +32,7 @@ .\" @(#)strftime.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 25, 2012 +.Dd November 2, 2021 .Dt STRFTIME 3 .Os .Sh NAME @@ -154,6 +154,8 @@ is replaced by the minute as a decimal number (00-59). .It Cm %m is replaced by the month as a decimal number (01-12). +.It Cm %N +is replaced by the nanosecond as a decimal number (000000000-999999999). .It Cm %n is replaced by a newline. .It Cm %O* @@ -257,6 +259,7 @@ .Ql %h , .Ql %k , .Ql %l , +.Ql %N , .Ql %n , .Ql %O* , .Ql \&%R , Index: lib/libc/stdtime/strftime.c =================================================================== --- lib/libc/stdtime/strftime.c +++ lib/libc/stdtime/strftime.c @@ -41,6 +41,7 @@ #include "tzfile.h" #include +#include #include #include "un-namespace.h" #include "timelocal.h" @@ -83,7 +84,9 @@ #define PAD_FMT_DAYOFYEAR 2 { "%03d", "%d", "%3d", "%03d" }, #define PAD_FMT_YEAR 3 - { "%04d", "%d", "%4d", "%04d" } + { "%04d", "%d", "%4d", "%04d" }, +#define PAD_FMT_NANOSECONDS 4 + { "%09d", "%d", "%9d", "%09d" } }; size_t @@ -130,6 +133,7 @@ _fmt(const char *format, const struct tm * const t, char *pt, const char * const ptlim, int *warnp, locale_t loc) { + struct timespec tspec; int Ealternative, Oalternative, PadIndex; struct lc_time_T *tptr = __get_current_time_locale(loc); @@ -290,6 +294,12 @@ fmt_padding[PAD_FMT_MONTH][PadIndex], pt, ptlim, loc); continue; + case 'N': + clock_gettime(CLOCK_REALTIME_FAST, &tspec); + pt = _conv(tspec.tv_nsec, + fmt_padding[PAD_FMT_NANOSECONDS][PadIndex], + pt, ptlim, loc); + continue; case 'n': pt = _add("\n", pt, ptlim); continue;