summaryrefslogtreecommitdiff
path: root/usr.bin/touch
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2011-08-30 02:07:12 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2011-08-30 02:07:12 +0000
commit916d411ba3d8498c294f4fb41bdb7f8ac8e01566 (patch)
tree8d3d25720d2cd6b2241c62efb1316e87bfe4193b /usr.bin/touch
parentd3f36b08c23d6fb250d1dc5bd08439dfae37d5f8 (diff)
Make the code match the manpage and POSIX spec when the year is specified
but the century isn't: century is 1900 if year >= 69; else 2000 ok millert@
Diffstat (limited to 'usr.bin/touch')
-rw-r--r--usr.bin/touch/touch.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/usr.bin/touch/touch.c b/usr.bin/touch/touch.c
index d5c329dda5c..aa0d643b23b 100644
--- a/usr.bin/touch/touch.c
+++ b/usr.bin/touch/touch.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: touch.c,v 1.19 2011/08/21 20:55:23 guenther Exp $ */
+/* $OpenBSD: touch.c,v 1.20 2011/08/30 02:07:11 guenther Exp $ */
/* $NetBSD: touch.c,v 1.11 1995/08/31 22:10:06 jtc Exp $ */
/*
@@ -189,8 +189,10 @@ stime_arg1(char *arg, struct timespec *tsp)
lt->tm_year += yearset;
} else {
yearset = ATOI2(arg);
- /* Preserve current century. */
- lt->tm_year = ((lt->tm_year / 100) * 100) + yearset;
+ /* POSIX logic: [00,68]=>20xx, [69,99]=>19xx */
+ lt->tm_year = yearset + 1900 - TM_YEAR_BASE;
+ if (yearset < 69)
+ lt->tm_year += 100;
}
/* FALLTHROUGH */
case 8: /* MMDDhhmm */
@@ -245,8 +247,11 @@ stime_arg2(char *arg, int year, struct timespec *tsp)
if (lt->tm_min > 59)
goto terr;
if (year) {
- year = ATOI2(arg); /* Preserve current century. */
- lt->tm_year = ((lt->tm_year / 100) * 100) + year;
+ year = ATOI2(arg);
+ /* POSIX logic: [00,68]=>20xx, [69,99]=>19xx */
+ lt->tm_year = year + 1900 - TM_YEAR_BASE;
+ if (year < 69)
+ lt->tm_year += 100;
}
lt->tm_sec = 0;