tadd vttimefmt - plan9port - [fork] Plan 9 from user space
HTML git clone git://src.adamsgaard.dk/plan9port
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
DIR commit d20564a9a6d75192ec21170f2c6cd699eb361d96
DIR parent 2bdefab1da7bc64f433cba5871fc57d5524a06e1
HTML Author: rsc <devnull@localhost>
Date: Tue, 18 Jul 2006 15:23:58 +0000
add vttimefmt
Diffstat:
M include/venti.h | 2 ++
M src/libventi/mkfile | 1 +
A src/libventi/time.c | 25 +++++++++++++++++++++++++
3 files changed, 28 insertions(+), 0 deletions(-)
---
DIR diff --git a/include/venti.h b/include/venti.h
t@@ -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;
DIR diff --git a/src/libventi/mkfile b/src/libventi/mkfile
t@@ -27,6 +27,7 @@ OFILES=\
srvhello.$O\
strdup.$O\
string.$O\
+ time.$O\
version.$O\
zero.$O\
zeroscore.$O\
DIR diff --git a/src/libventi/time.c b/src/libventi/time.c
t@@ -0,0 +1,25 @@
+#include <u.h>
+#include <libc.h>
+#include <venti.h>
+
+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);
+ }
+}
+