1
0
mirror of https://github.com/golang/go synced 2024-11-23 21:10:05 -07:00

lib9: add ctime

ctime differs across Unix vs Plan 9 so add to portability library

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5363043
This commit is contained in:
Russ Cox 2011-11-07 13:15:16 -05:00
parent 1c42db8835
commit 3f4a91d778
4 changed files with 33 additions and 5 deletions

View File

@ -95,6 +95,7 @@ extern void perror(const char*);
extern int postnote(int, int, char *);
extern double p9pow10(int);
extern char* searchpath(char*);
extern char* p9ctime(long);
#define p9setjmp(b) sigsetjmp((void*)(b), 1)
extern void sysfatal(char*, ...);
@ -115,6 +116,7 @@ extern void sysfatal(char*, ...);
#undef strtod
#define strtod fmtstrtod
#define charstod fmtcharstod
#define ctime p9ctime
#endif
/*

View File

@ -1420,15 +1420,12 @@ void
longt(Armember *bp)
{
char *cp;
time_t date;
pmode(strtoul(bp->hdr.mode, 0, 8));
Bprint(&bout, "%3ld/%1ld", strtol(bp->hdr.uid, 0, 0), strtol(bp->hdr.gid, 0, 0));
Bprint(&bout, "%7ld", bp->size);
date = bp->date;
cp = ctime(&date);
/* using unix ctime, not plan 9 time, so cp+20 for year, not cp+24 */
Bprint(&bout, " %-12.12s %-4.4s ", cp+4, cp+20);
cp = ctime(bp->date);
Bprint(&bout, " %-12.12s %-4.4s ", cp+4, cp+24);
}
int m1[] = { 1, ROWN, 'r', '-' };

View File

@ -57,6 +57,7 @@ LIB9OFILES=\
atoi.$O\
cleanname.$O\
create.$O\
ctime.$O\
dirfstat.$O\
dirfwstat.$O\
dirstat.$O\

28
src/lib9/ctime.c Normal file
View File

@ -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;
}