diff options
author | Russ Cox <rsc@golang.org> | 2011-11-07 13:15:16 -0500 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-11-07 13:15:16 -0500 |
commit | 5c218389af261d02fd964c55572bd6adfa037034 (patch) | |
tree | f3e2fb4c2a17f22f3bdd6097978e873128f3cc5e /src/lib9 | |
parent | 5b07b06e9bac0bac5cb0dfa1afe8895e295264dd (diff) | |
download | go-5c218389af261d02fd964c55572bd6adfa037034.tar.gz |
lib9: add ctime
ctime differs across Unix vs Plan 9 so add to portability library
R=golang-dev, r
CC=golang-dev
http://codereview.appspot.com/5363043
Diffstat (limited to 'src/lib9')
-rw-r--r-- | src/lib9/Makefile | 1 | ||||
-rw-r--r-- | src/lib9/ctime.c | 28 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/lib9/Makefile b/src/lib9/Makefile index 28c97c9b4..31f22c41e 100644 --- a/src/lib9/Makefile +++ b/src/lib9/Makefile @@ -57,6 +57,7 @@ LIB9OFILES=\ atoi.$O\ cleanname.$O\ create.$O\ + ctime.$O\ dirfstat.$O\ dirfwstat.$O\ dirstat.$O\ diff --git a/src/lib9/ctime.c b/src/lib9/ctime.c new file mode 100644 index 000000000..d4ab6b21a --- /dev/null +++ b/src/lib9/ctime.c @@ -0,0 +1,28 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#define NOPLAN9DEFINES +#include <u.h> +#include <libc.h> + +char* +p9ctime(long t) +{ + static char buf[100]; + time_t tt; + struct tm *tm; + + tt = t; + tm = localtime(&tt); + snprint(buf, sizeof buf, "%3.3s %3.3s %02d %02d:%02d:%02d %3.3s %d\n", + "SunMonTueWedThuFriSat"+(tm->tm_wday*3), + "JanFebMarAprMayJunJulAugSepOctNovDec"+(tm->tm_mon*3), + tm->tm_mday, + tm->tm_hour, + tm->tm_min, + tm->tm_sec, + tm->tm_zone, + tm->tm_year + 1900); + return buf; +} |