mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
On snap 950210, format %s (print seconds from the epoch) is missing
from the code in strftime.c . This affects both the library code and all the commands using it (e.g. date +%s). Note that %s is not required by ANSI, but we've already got it in 1.1.5.1. Suggested by: luigi@labinfo.iet.unipi.it (Luigi Rizzo)
This commit is contained in:
parent
c30c84ed1f
commit
be7f0d04fe
2 changed files with 23 additions and 1 deletions
|
|
@ -141,7 +141,7 @@ is replaced by a tab.
|
|||
.It Cm \&%S
|
||||
is replaced by the second as a decimal number (00-60).
|
||||
.It Cm %s
|
||||
is replaced by the number of seconds since the Epoch, UCT (see
|
||||
is replaced by the number of seconds since the Epoch, UTC (see
|
||||
.Xr mktime 3 ) .
|
||||
.It Cm \&%T No or Cm \&%X
|
||||
is equivalent to
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ static const char Bfmt[][10] = {
|
|||
static char *_add P((const char *, char *, const char *));
|
||||
static char *_conv P((int, const char *, char *, const char *));
|
||||
static char *_fmt P((const char *, const struct tm *, char *, const char *));
|
||||
static char *_secs P((const struct tm *, char *, const char *));
|
||||
|
||||
size_t strftime P((char *, size_t, const char *, const struct tm *));
|
||||
|
||||
|
|
@ -232,6 +233,9 @@ label:
|
|||
case 'S':
|
||||
pt = _conv(t->tm_sec, "%02d", pt, ptlim);
|
||||
continue;
|
||||
case 's':
|
||||
pt = _secs(t, pt, ptlim);
|
||||
continue;
|
||||
case 'T':
|
||||
case 'X':
|
||||
pt = _fmt("%H:%M:%S", t, pt, ptlim);
|
||||
|
|
@ -381,6 +385,24 @@ _conv(n, format, pt, ptlim)
|
|||
return _add(buf, pt, ptlim);
|
||||
}
|
||||
|
||||
static char *
|
||||
_secs(t, pt, ptlim)
|
||||
const struct tm *t;
|
||||
char *pt;
|
||||
const char *ptlim;
|
||||
{
|
||||
static char buf[INT_STRLEN_MAXIMUM(int) + 1];
|
||||
register time_t s;
|
||||
register char *p;
|
||||
struct tm tmp;
|
||||
|
||||
/* Make a copy, mktime(3) modifies the tm struct. */
|
||||
tmp = *t;
|
||||
s = mktime(&tmp);
|
||||
(void) sprintf(buf, "%d", s);
|
||||
return(_add(buf, pt, ptlim));
|
||||
}
|
||||
|
||||
static char *
|
||||
_add(str, pt, ptlim)
|
||||
const char *str;
|
||||
|
|
|
|||
Loading…
Reference in a new issue