Check fgets' return value, silent -Wall.

Obtained from: OpenBSD
This commit is contained in:
charnier 1997-07-21 12:04:31 +00:00
parent 6fc33a9dac
commit 12747632ef
2 changed files with 22 additions and 11 deletions

View File

@ -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 .

View File

@ -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 <sys/param.h>
#include <sys/time.h>
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <unistd.h>
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");