summaryrefslogtreecommitdiffstats
path: root/bin/date
diff options
context:
space:
mode:
authorbde <bde@FreeBSD.org>1994-12-26 12:59:28 +0000
committerbde <bde@FreeBSD.org>1994-12-26 12:59:28 +0000
commitc73adf1de827e599d3b3e4d1c5938fcc32b30209 (patch)
treeae34feaa03292b0105d99eea8ad5bcc0f8f49e50 /bin/date
parent6476aa24f141e28eac4c220933f71eea99c98905 (diff)
downloadFreeBSD-src-c73adf1de827e599d3b3e4d1c5938fcc32b30209.zip
FreeBSD-src-c73adf1de827e599d3b3e4d1c5938fcc32b30209.tar.gz
Obtained from: partly from 386BSD-0.1.2.4
Fix several bugs involving the obsolescent -d and -t options: -d 0 and -t 0 were ignored -t -600 was a usage error -d 'atoi is not suitable for parsing args' and -t duh were not usage errors Change some error messages to say which call to settimeofday failed. Restore casts of NULL in function calls. Finish conversion to using err() instead of perror().
Diffstat (limited to 'bin/date')
-rw-r--r--bin/date/date.c31
1 files changed, 17 insertions, 14 deletions
diff --git a/bin/date/date.c b/bin/date/date.c
index cff1caa..1098046 100644
--- a/bin/date/date.c
+++ b/bin/date/date.c
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id$
+ * $Id: date.c,v 1.2 1994/09/24 02:54:36 davidg Exp $
*/
#ifndef lint
@@ -76,13 +76,19 @@ main(argc, argv)
struct timezone tz;
int ch, rflag;
char *format, buf[1024];
+ char *endptr;
+ int set_timezone;
tz.tz_dsttime = tz.tz_minuteswest = 0;
rflag = 0;
+ set_timezone = 0;
while ((ch = getopt(argc, argv, "d:nr:ut:")) != EOF)
switch((char)ch) {
case 'd': /* daylight savings time */
- tz.tz_dsttime = atoi(optarg) ? 1 : 0;
+ tz.tz_dsttime = strtol(optarg, &endptr, 10) ? 1 : 0;
+ if (endptr == optarg || *endptr != '\0')
+ usage();
+ set_timezone = 1;
break;
case 'n': /* don't set network */
nflag = 1;
@@ -96,11 +102,11 @@ main(argc, argv)
break;
case 't': /* minutes west of GMT */
/* error check; don't allow "PST" */
- if (isdigit(*optarg)) {
- tz.tz_minuteswest = atoi(optarg);
- break;
- }
- /* FALLTHROUGH */
+ tz.tz_minuteswest = strtol(optarg, &endptr, 10);
+ if (endptr == optarg || *endptr != '\0')
+ usage();
+ set_timezone = 1;
+ break;
default:
usage();
}
@@ -111,9 +117,8 @@ main(argc, argv)
* If -d or -t, set the timezone or daylight savings time; this
* doesn't belong here, there kernel should not know about either.
*/
- if ((tz.tz_minuteswest || tz.tz_dsttime) &&
- settimeofday(NULL, &tz))
- err(1, "settimeofday");
+ if (set_timezone && settimeofday((struct timeval *)NULL, &tz))
+ err(1, "settimeofday (timezone)");
if (!rflag && time(&tval) == -1)
err(1, "time");
@@ -210,10 +215,8 @@ setthetime(p)
logwtmp("|", "date", "");
tv.tv_sec = tval;
tv.tv_usec = 0;
- if (settimeofday(&tv, NULL)) {
- perror("date: settimeofday");
- exit(1);
- }
+ if (settimeofday(&tv, (struct timezone *)NULL))
+ err(1, "settimeofday (timeval)");
logwtmp("{", "date", "");
}
OpenPOWER on IntegriCloud