Commit 3f4a91d7 authored by Russ Cox's avatar Russ Cox

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
parent 1c42db88
......@@ -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
/*
......
......@@ -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', '-' };
......
......@@ -57,6 +57,7 @@ LIB9OFILES=\
atoi.$O\
cleanname.$O\
create.$O\
ctime.$O\
dirfstat.$O\
dirfwstat.$O\
dirstat.$O\
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment