]> Cypherpunks repositories - gostls13.git/commitdiff
lib9: add ctime
authorRuss Cox <rsc@golang.org>
Mon, 7 Nov 2011 18:15:16 +0000 (13:15 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 7 Nov 2011 18:15:16 +0000 (13:15 -0500)
ctime differs across Unix vs Plan 9 so add to portability library

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/5363043

include/libc.h
src/cmd/gopack/ar.c
src/lib9/Makefile
src/lib9/ctime.c [new file with mode: 0644]

index f9ad963345a577b98cfe6fb789e0ec1af1bdaebc..0b50eb3c5fd6e37abf527f303ce4c9a2d17d17e9 100644 (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
 
 /*
index 9125f2987eb4eaa434402f2306239b6a6e9e0de3..bd3bcefeb501ddab53518d4843aa4bc318279a6a 100644 (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', '-' };
index 28c97c9b4564bd105489388cfb064e8bba1671e3..31f22c41e966b5d013c2ee25cdddd73d923204ef 100644 (file)
@@ -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 (file)
index 0000000..d4ab6b2
--- /dev/null
@@ -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;
+}