Check fgets' return value, silent -Wall.
Obtained from: OpenBSD
This commit is contained in:
parent
342548bf0f
commit
492dbf7344
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=27572
@ -38,7 +38,7 @@
|
|||||||
.Nm leave
|
.Nm leave
|
||||||
.Nd remind you when you have to leave
|
.Nd remind you when you have to leave
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm leave
|
.Nm
|
||||||
.Sm off
|
.Sm off
|
||||||
.Oo
|
.Oo
|
||||||
.Op Cm \&+
|
.Op Cm \&+
|
||||||
@ -52,7 +52,7 @@ have to leave.
|
|||||||
You are reminded 5 minutes and 1 minute before the actual
|
You are reminded 5 minutes and 1 minute before the actual
|
||||||
time, at the time, and every minute thereafter.
|
time, at the time, and every minute thereafter.
|
||||||
When you log off,
|
When you log off,
|
||||||
.Nm leave
|
.Nm
|
||||||
exits just before it would have
|
exits just before it would have
|
||||||
printed the next message.
|
printed the next message.
|
||||||
.Pp
|
.Pp
|
||||||
@ -78,16 +78,16 @@ from the current time.
|
|||||||
.El
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
If no argument is given,
|
If no argument is given,
|
||||||
.Nm leave
|
.Nm
|
||||||
prompts with "When do you
|
prompts with "When do you
|
||||||
have to leave?". A reply of newline causes
|
have to leave?". A reply of newline causes
|
||||||
.Nm leave
|
.Nm
|
||||||
to exit,
|
to exit,
|
||||||
otherwise the reply is assumed to be a time.
|
otherwise the reply is assumed to be a time.
|
||||||
This form is suitable for inclusion in a
|
This form is suitable for inclusion in a
|
||||||
.Pa .login
|
.Pa .login
|
||||||
or
|
or
|
||||||
.Pa .profile.
|
.Pa .profile .
|
||||||
.Pp
|
.Pp
|
||||||
Leave ignores interrupts, quits, and terminates.
|
Leave ignores interrupts, quits, and terminates.
|
||||||
To get rid of it you should either log off or use
|
To get rid of it you should either log off or use
|
||||||
@ -97,6 +97,6 @@ giving its process id.
|
|||||||
.Xr calendar 1
|
.Xr calendar 1
|
||||||
.Sh HISTORY
|
.Sh HISTORY
|
||||||
The
|
The
|
||||||
.Nm leave
|
.Nm
|
||||||
command appeared in
|
command appeared in
|
||||||
.Bx 3.0 .
|
.Bx 3.0 .
|
||||||
|
@ -32,19 +32,27 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char copyright[] =
|
static const char copyright[] =
|
||||||
"@(#) Copyright (c) 1980, 1988, 1993\n\
|
"@(#) Copyright (c) 1980, 1988, 1993\n\
|
||||||
The Regents of the University of California. All rights reserved.\n";
|
The Regents of the University of California. All rights reserved.\n";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
|
#if 0
|
||||||
static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
|
static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
|
||||||
|
#endif
|
||||||
|
static const char rcsid[] =
|
||||||
|
"$Id$";
|
||||||
#endif /* not lint */
|
#endif /* not lint */
|
||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
void doalarm __P((u_int));
|
||||||
|
static void usage __P((void));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* leave [[+]hhmm]
|
* 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.
|
* Leave prompts for input and goes away if you hit return.
|
||||||
* It nags you like a mother hen.
|
* It nags you like a mother hen.
|
||||||
*/
|
*/
|
||||||
|
int
|
||||||
main(argc, argv)
|
main(argc, argv)
|
||||||
int argc;
|
int argc;
|
||||||
char **argv;
|
char **argv;
|
||||||
@ -69,7 +78,7 @@ main(argc, argv)
|
|||||||
#define MSG1 "When do you have to leave? "
|
#define MSG1 "When do you have to leave? "
|
||||||
(void)write(1, MSG1, sizeof(MSG1) - 1);
|
(void)write(1, MSG1, sizeof(MSG1) - 1);
|
||||||
cp = fgets(buf, sizeof(buf), stdin);
|
cp = fgets(buf, sizeof(buf), stdin);
|
||||||
if (*cp == '\n')
|
if (cp == NULL || *cp == '\n')
|
||||||
exit(0);
|
exit(0);
|
||||||
} else
|
} else
|
||||||
cp = argv[1];
|
cp = argv[1];
|
||||||
@ -97,7 +106,7 @@ main(argc, argv)
|
|||||||
secs = hours * 60 * 60 + minutes * 60;
|
secs = hours * 60 * 60 + minutes * 60;
|
||||||
else {
|
else {
|
||||||
if (hours > 23 || t->tm_hour > hours ||
|
if (hours > 23 || t->tm_hour > hours ||
|
||||||
t->tm_hour == hours && minutes <= t->tm_min)
|
(t->tm_hour == hours && minutes <= t->tm_min))
|
||||||
usage();
|
usage();
|
||||||
secs = (hours - t->tm_hour) * 60 * 60;
|
secs = (hours - t->tm_hour) * 60 * 60;
|
||||||
secs += (minutes - t->tm_min) * 60;
|
secs += (minutes - t->tm_min) * 60;
|
||||||
@ -106,6 +115,7 @@ main(argc, argv)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
doalarm(secs)
|
doalarm(secs)
|
||||||
u_int secs;
|
u_int secs;
|
||||||
{
|
{
|
||||||
@ -114,7 +124,7 @@ doalarm(secs)
|
|||||||
int pid;
|
int pid;
|
||||||
char *ctime();
|
char *ctime();
|
||||||
|
|
||||||
if (pid = fork()) {
|
if ((pid = fork())) {
|
||||||
(void)time(&daytime);
|
(void)time(&daytime);
|
||||||
daytime += secs;
|
daytime += secs;
|
||||||
printf("Alarm set for %.16s. (pid %d)\n",
|
printf("Alarm set for %.16s. (pid %d)\n",
|
||||||
@ -156,6 +166,7 @@ doalarm(secs)
|
|||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "usage: leave [[+]hhmm]\n");
|
fprintf(stderr, "usage: leave [[+]hhmm]\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user