summaryrefslogtreecommitdiff
path: root/usr.bin/find/ls.c
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2014-01-10 04:53:36 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2014-01-10 04:53:36 +0000
commit9abb997ec93fa87cef1566d3249414706d7db72e (patch)
tree3c87921ca976e1186cd57beeb33a1b8ad8d04549 /usr.bin/find/ls.c
parent47e1c02b99ab6ac3430e9f18c1fc94e62e799387 (diff)
Copy changes from ls -l to find -ls: print future times with year and use
strftime() instead of parsing ctime()'s output. ok millert@
Diffstat (limited to 'usr.bin/find/ls.c')
-rw-r--r--usr.bin/find/ls.c35
1 files changed, 19 insertions, 16 deletions
diff --git a/usr.bin/find/ls.c b/usr.bin/find/ls.c
index 66680561708..b78ae1734a7 100644
--- a/usr.bin/find/ls.c
+++ b/usr.bin/find/ls.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ls.c,v 1.14 2013/04/23 18:08:40 deraadt Exp $ */
+/* $OpenBSD: ls.c,v 1.15 2014/01/10 04:53:35 guenther Exp $ */
/*
* Copyright (c) 1989, 1993
@@ -52,6 +52,8 @@ static void printlink(char *);
static void printtime(time_t);
#define NAME_WIDTH 8
+#define DATELEN 64
+#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY)
void
printlong(char *name, char *accpath, struct stat *sb)
@@ -80,23 +82,24 @@ printlong(char *name, char *accpath, struct stat *sb)
static void
printtime(time_t ftime)
{
- int i;
- char *longstring;
-
- longstring = ctime(&ftime);
- for (i = 4; i < 11; ++i)
- (void)putchar(longstring[i]);
+ char f_date[DATELEN];
+ static time_t now;
+ static int now_set = 0;
-#define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY)
- if (ftime + SIXMONTHS > time(NULL))
- for (i = 11; i < 16; ++i)
- (void)putchar(longstring[i]);
- else {
- (void)putchar(' ');
- for (i = 20; i < 24; ++i)
- (void)putchar(longstring[i]);
+ if (! now_set) {
+ now = time(NULL);
+ now_set = 1;
}
- (void)putchar(' ');
+
+ /*
+ * convert time to string, and print
+ */
+ if (strftime(f_date, sizeof(f_date),
+ (ftime + SIXMONTHS <= now || ftime > now) ? "%b %e %Y" :
+ "%b %e %H:%M", localtime(&ftime)) == 0)
+ f_date[0] = '\0';
+
+ printf("%s ", f_date);
}
static void