From d20564a9a6d75192ec21170f2c6cd699eb361d96 Mon Sep 17 00:00:00 2001 From: rsc Date: Tue, 18 Jul 2006 15:23:58 +0000 Subject: add vttimefmt --- include/venti.h | 2 ++ src/libventi/mkfile | 1 + src/libventi/time.c | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 src/libventi/time.c diff --git a/include/venti.h b/include/venti.h index c4538a90..9fea5bcf 100644 --- a/include/venti.h +++ b/include/venti.h @@ -488,6 +488,8 @@ uvlong vtfilegetsize(VtFile*); int vtfilesetsize(VtFile*, u64int); int vtfileremove(VtFile*); +extern int vttimefmt(Fmt*); + extern int chattyventi; extern int ventidoublechecksha1; extern int ventilogging; diff --git a/src/libventi/mkfile b/src/libventi/mkfile index 2e7d04b3..289262ac 100644 --- a/src/libventi/mkfile +++ b/src/libventi/mkfile @@ -27,6 +27,7 @@ OFILES=\ srvhello.$O\ strdup.$O\ string.$O\ + time.$O\ version.$O\ zero.$O\ zeroscore.$O\ diff --git a/src/libventi/time.c b/src/libventi/time.c new file mode 100644 index 00000000..2d8058f1 --- /dev/null +++ b/src/libventi/time.c @@ -0,0 +1,25 @@ +#include +#include +#include + +int +vttimefmt(Fmt *fmt) +{ + vlong ns; + Tm tm; + + if(fmt->flags&FmtLong){ + ns = nsec(); + tm = *localtime(ns/1000000000); + return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d.%03d", + tm.year+1900, tm.mon+1, tm.mday, + tm.hour, tm.min, tm.sec, + (int)(ns%1000000000)/1000000); + }else{ + tm = *localtime(time(0)); + return fmtprint(fmt, "%04d/%02d%02d %02d:%02d:%02d", + tm.year+1900, tm.mon+1, tm.mday, + tm.hour, tm.min, tm.sec); + } +} + -- cgit v1.2.3