summaryrefslogtreecommitdiffstats
path: root/usr.bin/leave
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-21 12:04:31 +0000
committercharnier <charnier@FreeBSD.org>1997-07-21 12:04:31 +0000
commit12747632ef062c34c6c11e0d9fcf4c0dfe3568aa (patch)
tree61b24da2e6f4a8ae9c1df88733a183253f56c01f /usr.bin/leave
parent6fc33a9dac1b111924ffab8c40d92bdd6f641583 (diff)
downloadFreeBSD-src-12747632ef062c34c6c11e0d9fcf4c0dfe3568aa.zip
FreeBSD-src-12747632ef062c34c6c11e0d9fcf4c0dfe3568aa.tar.gz
Check fgets' return value, silent -Wall.
Obtained from: OpenBSD
Diffstat (limited to 'usr.bin/leave')
-rw-r--r--usr.bin/leave/leave.112
-rw-r--r--usr.bin/leave/leave.c21
2 files changed, 22 insertions, 11 deletions
diff --git a/usr.bin/leave/leave.1 b/usr.bin/leave/leave.1
index cca4e5b..f7cbed8 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 56d9d19..2129936 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 <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");
OpenPOWER on IntegriCloud