diff options
author | joerg <joerg@FreeBSD.org> | 1995-03-01 23:08:40 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1995-03-01 23:08:40 +0000 |
commit | e8c06a9513ade8cda989aadc92beefcb5596acf0 (patch) | |
tree | 8db609b5164ee926b5ca0ed49c6d1b60091a855c /lib/libc/stdtime | |
parent | e77e1f47174a626361d4397e18fe84509556dfbb (diff) | |
download | FreeBSD-src-e8c06a9513ade8cda989aadc92beefcb5596acf0.zip FreeBSD-src-e8c06a9513ade8cda989aadc92beefcb5596acf0.tar.gz |
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)
Diffstat (limited to 'lib/libc/stdtime')
-rw-r--r-- | lib/libc/stdtime/strftime.3 | 2 | ||||
-rw-r--r-- | lib/libc/stdtime/strftime.c | 22 |
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/libc/stdtime/strftime.3 b/lib/libc/stdtime/strftime.3 index 3da35a1..fd510ba 100644 --- a/lib/libc/stdtime/strftime.3 +++ b/lib/libc/stdtime/strftime.3 @@ -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 diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index 821bc79..1c50d65 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -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); @@ -382,6 +386,24 @@ _conv(n, format, 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; char *pt; |