From 492dbf7344031f6552a90eb77fb4a706a369074e Mon Sep 17 00:00:00 2001 From: Philippe Charnier Date: Mon, 21 Jul 1997 12:04:31 +0000 Subject: [PATCH] Check fgets' return value, silent -Wall. Obtained from: OpenBSD --- usr.bin/leave/leave.1 | 12 ++++++------ usr.bin/leave/leave.c | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/usr.bin/leave/leave.1 b/usr.bin/leave/leave.1 index cca4e5b6b292..f7cbed851fb0 100644 --- a/usr.bin/leave/leave.1 +++ b/usr.bin/leave/leave.1 @@ -38,7 +38,7 @@ .Nm leave .Nd remind you when you have to leave .Sh SYNOPSIS -.Nm leave +.Nm .Sm off .Oo .Op Cm \&+ @@ -52,7 +52,7 @@ have to leave. You are reminded 5 minutes and 1 minute before the actual time, at the time, and every minute thereafter. When you log off, -.Nm leave +.Nm exits just before it would have printed the next message. .Pp @@ -78,16 +78,16 @@ from the current time. .El .Pp If no argument is given, -.Nm leave +.Nm prompts with "When do you have to leave?". A reply of newline causes -.Nm leave +.Nm to exit, otherwise the reply is assumed to be a time. This form is suitable for inclusion in a .Pa .login or -.Pa .profile. +.Pa .profile . .Pp Leave ignores interrupts, quits, and terminates. To get rid of it you should either log off or use @@ -97,6 +97,6 @@ giving its process id. .Xr calendar 1 .Sh HISTORY The -.Nm leave +.Nm command appeared in .Bx 3.0 . diff --git a/usr.bin/leave/leave.c b/usr.bin/leave/leave.c index 56d9d19fa479..212993600a05 100644 --- a/usr.bin/leave/leave.c +++ b/usr.bin/leave/leave.c @@ -32,19 +32,27 @@ */ #ifndef lint -static char copyright[] = +static const char copyright[] = "@(#) Copyright (c) 1980, 1988, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint +#if 0 static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93"; +#endif +static const char rcsid[] = + "$Id$"; #endif /* not lint */ #include #include -#include #include +#include +#include + +void doalarm __P((u_int)); +static void usage __P((void)); /* * leave [[+]hhmm] @@ -53,6 +61,7 @@ static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93"; * Leave prompts for input and goes away if you hit return. * It nags you like a mother hen. */ +int main(argc, argv) int argc; char **argv; @@ -69,7 +78,7 @@ main(argc, argv) #define MSG1 "When do you have to leave? " (void)write(1, MSG1, sizeof(MSG1) - 1); cp = fgets(buf, sizeof(buf), stdin); - if (*cp == '\n') + if (cp == NULL || *cp == '\n') exit(0); } else cp = argv[1]; @@ -97,7 +106,7 @@ main(argc, argv) secs = hours * 60 * 60 + minutes * 60; else { if (hours > 23 || t->tm_hour > hours || - t->tm_hour == hours && minutes <= t->tm_min) + (t->tm_hour == hours && minutes <= t->tm_min)) usage(); secs = (hours - t->tm_hour) * 60 * 60; secs += (minutes - t->tm_min) * 60; @@ -106,6 +115,7 @@ main(argc, argv) exit(0); } +void doalarm(secs) u_int secs; { @@ -114,7 +124,7 @@ doalarm(secs) int pid; char *ctime(); - if (pid = fork()) { + if ((pid = fork())) { (void)time(&daytime); daytime += secs; printf("Alarm set for %.16s. (pid %d)\n", @@ -156,6 +166,7 @@ doalarm(secs) exit(0); } +static void usage() { fprintf(stderr, "usage: leave [[+]hhmm]\n");