summaryrefslogtreecommitdiff
path: root/bin/date/date.c
diff options
context:
space:
mode:
authorKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-16 00:33:37 -0500
committerKiyoshi Aman <kiyoshi.aman+adelie@gmail.com>2019-05-16 00:33:37 -0500
commit5aef04248e45a1a0ce74d96e78abd871048369bf (patch)
treed4e80e01e34504ac8d4c27b966612d2671867ce0 /bin/date/date.c
parent9d6d971d463053417e18e01095cc3c7bf722f892 (diff)
downloaduserland-5aef04248e45a1a0ce74d96e78abd871048369bf.tar.gz
userland-5aef04248e45a1a0ce74d96e78abd871048369bf.tar.bz2
userland-5aef04248e45a1a0ce74d96e78abd871048369bf.tar.xz
userland-5aef04248e45a1a0ce74d96e78abd871048369bf.zip
bin/date: make buildable via libbsd, remove unusable options
Diffstat (limited to 'bin/date/date.c')
-rw-r--r--bin/date/date.c81
1 files changed, 34 insertions, 47 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index a067457..313a7f1 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -29,21 +29,6 @@
* SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-#ifndef lint
-__COPYRIGHT(
-"@(#) Copyright (c) 1985, 1987, 1988, 1993\
- The Regents of the University of California. All rights reserved.");
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)date.c 8.2 (Berkeley) 4/28/95";
-#else
-__RCSID("$NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $");
-#endif
-#endif /* not lint */
-
#include <sys/param.h>
#include <sys/time.h>
@@ -54,21 +39,24 @@ __RCSID("$NetBSD: date.c,v 1.61 2014/09/01 21:42:21 dholland Exp $");
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
+#include <bsd/stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
-#include <tzfile.h>
#include <unistd.h>
-#include <util.h>
+#include <utmpx.h>
+#include <stdbool.h>
#include "extern.h"
+#define TM_YEAR_BASE 1900
+
static time_t tval;
static int aflag, jflag, rflag, nflag;
-__dead static void badcanotime(const char *, const char *, size_t);
+static void badcanotime(const char *, const char *, size_t);
static void setthetime(const char *);
-__dead static void usage(void);
+static void usage(void);
int
main(int argc, char *argv[])
@@ -83,26 +71,15 @@ main(int argc, char *argv[])
setprogname(argv[0]);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "ad:jnr:u")) != -1) {
+ while ((ch = getopt(argc, argv, "a:jnr:u")) != -1) {
switch (ch) {
case 'a': /* adjust time slowly */
aflag = 1;
nflag = 1;
break;
- case 'd':
- rflag = 1;
- tval = parsedate(optarg, NULL, NULL);
- if (tval == -1) {
- errx(EXIT_FAILURE,
- "%s: Unrecognized date format", optarg);
- }
- break;
case 'j': /* don't set time */
jflag = 1;
break;
- case 'n': /* don't set network */
- nflag = 1;
- break;
case 'r': /* user specified seconds */
if (optarg[0] == '\0') {
errx(EXIT_FAILURE, "<empty>: Invalid number");
@@ -165,6 +142,18 @@ bad:
err(EXIT_FAILURE, "Cannot allocate format buffer");
}
+static inline bool
+isleap(int year) {
+ if ((year % 100) == 0) {
+ if ((year % 400) != 0) {
+ return false;
+ }
+ } else if (year % 4) {
+ return false;
+ }
+ return true;
+}
+
static void
badcanotime(const char *msg, const char *val, size_t where)
{
@@ -330,22 +319,20 @@ setthetime(const char *p)
}
/* set the time */
- if (nflag || netsettime(new_time)) {
- logwtmp("|", "date", "");
- if (aflag) {
- tv.tv_sec = new_time - tval;
- tv.tv_usec = 0;
- if (adjtime(&tv, NULL))
- err(EXIT_FAILURE, "adjtime");
- } else {
- tval = new_time;
- tv.tv_sec = tval;
- tv.tv_usec = 0;
- if (settimeofday(&tv, NULL))
- err(EXIT_FAILURE, "settimeofday");
- }
- logwtmp("{", "date", "");
+ logwtmp("|", "date", "");
+ if (aflag) {
+ tv.tv_sec = new_time - tval;
+ tv.tv_usec = 0;
+ if (adjtime(&tv, NULL))
+ err(EXIT_FAILURE, "adjtime");
+ } else {
+ tval = new_time;
+ tv.tv_sec = tval;
+ tv.tv_usec = 0;
+ if (settimeofday(&tv, NULL))
+ err(EXIT_FAILURE, "settimeofday");
}
+ logwtmp("{", "date", "");
if ((p = getlogin()) == NULL)
p = "???";
@@ -356,7 +343,7 @@ static void
usage(void)
{
(void)fprintf(stderr,
- "Usage: %s [-ajnu] [-d date] [-r seconds] [+format]",
+ "Usage: %s [-aju] [-r seconds] [+format]",
getprogname());
(void)fprintf(stderr, " [[[[[[CC]yy]mm]dd]HH]MM[.SS]]\n");
exit(EXIT_FAILURE);