Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdtime/strftime.c
Show All 35 Lines | |||||
#if defined(LIBC_SCCS) && !defined(lint) | #if defined(LIBC_SCCS) && !defined(lint) | ||||
static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; | static const char sccsid[] = "@(#)strftime.c 5.4 (Berkeley) 3/14/89"; | ||||
#endif /* LIBC_SCCS and not lint */ | #endif /* LIBC_SCCS and not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "tzfile.h" | #include "tzfile.h" | ||||
#include <fcntl.h> | #include <fcntl.h> | ||||
#include <time.h> | |||||
#include <sys/stat.h> | #include <sys/stat.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "timelocal.h" | #include "timelocal.h" | ||||
static char * _add(const char *, char *, const char *); | static char * _add(const char *, char *, const char *); | ||||
static char * _conv(int, const char *, char *, const char *, locale_t); | static char * _conv(int, const char *, char *, const char *, locale_t); | ||||
static char * _fmt(const char *, const struct tm *, char *, const char *, | static char * _fmt(const char *, const struct tm *, char *, const char *, | ||||
int *, locale_t); | int *, locale_t); | ||||
Show All 26 Lines | |||||
#define PAD_FMT_DAYOFMONTH 0 | #define PAD_FMT_DAYOFMONTH 0 | ||||
{ "%02d", "%d", "%2d", "%02d" }, | { "%02d", "%d", "%2d", "%02d" }, | ||||
#define PAD_FMT_SDAYOFMONTH 1 | #define PAD_FMT_SDAYOFMONTH 1 | ||||
#define PAD_FMT_SHMS 1 | #define PAD_FMT_SHMS 1 | ||||
{ "%2d", "%d", "%2d", "%02d" }, | { "%2d", "%d", "%2d", "%02d" }, | ||||
#define PAD_FMT_DAYOFYEAR 2 | #define PAD_FMT_DAYOFYEAR 2 | ||||
{ "%03d", "%d", "%3d", "%03d" }, | { "%03d", "%d", "%3d", "%03d" }, | ||||
#define PAD_FMT_YEAR 3 | #define PAD_FMT_YEAR 3 | ||||
{ "%04d", "%d", "%4d", "%04d" } | { "%04d", "%d", "%4d", "%04d" }, | ||||
#define PAD_FMT_NANOSECONDS 4 | |||||
{ "%09d", "%d", "%9d", "%09d" } | |||||
}; | }; | ||||
size_t | size_t | ||||
strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format, | strftime_l(char * __restrict s, size_t maxsize, const char * __restrict format, | ||||
const struct tm * __restrict t, locale_t loc) | const struct tm * __restrict t, locale_t loc) | ||||
{ | { | ||||
char * p; | char * p; | ||||
int warn; | int warn; | ||||
Show All 30 Lines | |||||
{ | { | ||||
return strftime_l(s, maxsize, format, t, __get_locale()); | return strftime_l(s, maxsize, format, t, __get_locale()); | ||||
} | } | ||||
static char * | static char * | ||||
_fmt(const char *format, const struct tm * const t, char *pt, | _fmt(const char *format, const struct tm * const t, char *pt, | ||||
const char * const ptlim, int *warnp, locale_t loc) | const char * const ptlim, int *warnp, locale_t loc) | ||||
{ | { | ||||
struct timespec tspec; | |||||
int Ealternative, Oalternative, PadIndex; | int Ealternative, Oalternative, PadIndex; | ||||
struct lc_time_T *tptr = __get_current_time_locale(loc); | struct lc_time_T *tptr = __get_current_time_locale(loc); | ||||
for ( ; *format; ++format) { | for ( ; *format; ++format) { | ||||
if (*format == '%') { | if (*format == '%') { | ||||
Ealternative = 0; | Ealternative = 0; | ||||
Oalternative = 0; | Oalternative = 0; | ||||
PadIndex = PAD_DEFAULT; | PadIndex = PAD_DEFAULT; | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | #endif /* defined KITCHEN_SINK */ | ||||
continue; | continue; | ||||
case 'M': | case 'M': | ||||
pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex], | pt = _conv(t->tm_min, fmt_padding[PAD_FMT_HMS][PadIndex], | ||||
pt, ptlim, loc); | pt, ptlim, loc); | ||||
continue; | continue; | ||||
case 'm': | case 'm': | ||||
pt = _conv(t->tm_mon + 1, | pt = _conv(t->tm_mon + 1, | ||||
fmt_padding[PAD_FMT_MONTH][PadIndex], | fmt_padding[PAD_FMT_MONTH][PadIndex], | ||||
pt, ptlim, loc); | |||||
continue; | |||||
case 'N': | |||||
clock_gettime(CLOCK_REALTIME_FAST, &tspec); | |||||
0mp: I'm not sure if that's the right clock to use. | |||||
pt = _conv(tspec.tv_nsec, | |||||
fmt_padding[PAD_FMT_NANOSECONDS][PadIndex], | |||||
pt, ptlim, loc); | pt, ptlim, loc); | ||||
continue; | continue; | ||||
case 'n': | case 'n': | ||||
pt = _add("\n", pt, ptlim); | pt = _add("\n", pt, ptlim); | ||||
continue; | continue; | ||||
case 'p': | case 'p': | ||||
pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ? | pt = _add((t->tm_hour >= (HOURSPERDAY / 2)) ? | ||||
tptr->pm : tptr->am, | tptr->pm : tptr->am, | ||||
▲ Show 20 Lines • Show All 344 Lines • Show Last 20 Lines |
I'm not sure if that's the right clock to use.