summaryrefslogtreecommitdiff
path: root/usr.bin/leave/leave.c
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-08 09:34:45 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1997-09-08 09:34:45 +0000
commit9344d9cb78997b14ad97b1731424ff12aee8ef25 (patch)
treeb8f0b4447ecefcb683fd0a68df24fc063f93317b /usr.bin/leave/leave.c
parent16fb6017a5f6c5e49140db451622f61d6942a243 (diff)
bring 12 hour semantics in line with man page; mikel
Diffstat (limited to 'usr.bin/leave/leave.c')
-rw-r--r--usr.bin/leave/leave.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/usr.bin/leave/leave.c b/usr.bin/leave/leave.c
index 082ff2c8785..d53f5e07731 100644
--- a/usr.bin/leave/leave.c
+++ b/usr.bin/leave/leave.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: leave.c,v 1.2 1996/06/26 05:34:57 deraadt Exp $ */
+/* $OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $ */
/* $NetBSD: leave.c,v 1.4 1995/07/03 16:50:13 phil Exp $ */
/*
@@ -44,14 +44,19 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)leave.c 8.1 (Berkeley) 6/6/93";
#endif
-static char rcsid[] = "$OpenBSD: leave.c,v 1.2 1996/06/26 05:34:57 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: leave.c,v 1.3 1997/09/08 09:34:44 deraadt Exp $";
#endif /* not lint */
#include <sys/param.h>
#include <sys/time.h>
+#include <unistd.h>
+#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
+void usage __P((void));
+void doalarm __P((u_int secs));
+
/*
* leave [[+]hhmm]
*
@@ -59,6 +64,7 @@ static char rcsid[] = "$OpenBSD: leave.c,v 1.2 1996/06/26 05:34:57 deraadt Exp $
* 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;
@@ -66,14 +72,14 @@ main(argc, argv)
register u_int secs;
register int hours, minutes;
register char c, *cp;
- struct tm *t, *localtime();
- time_t now, time();
+ struct tm *t;
+ time_t now;
int plusnow;
char buf[50];
if (argc < 2) {
#define MSG1 "When do you have to leave? "
- (void)write(1, MSG1, sizeof(MSG1) - 1);
+ (void)write(STDOUT_FILENO, MSG1, sizeof(MSG1) - 1);
cp = fgets(buf, sizeof(buf), stdin);
if (cp == NULL || *cp == '\n')
exit(0);
@@ -102,9 +108,13 @@ main(argc, argv)
if (plusnow)
secs = hours * 60 * 60 + minutes * 60;
else {
- if (hours > 23 || t->tm_hour > hours ||
- t->tm_hour == hours && minutes <= t->tm_min)
+ if (hours > 23)
usage();
+ if (t->tm_hour >= 12)
+ t->tm_hour -= 12;
+ if (t->tm_hour > hours ||
+ (t->tm_hour == hours && minutes <= t->tm_min))
+ hours += 12;
secs = (hours - t->tm_hour) * 60 * 60;
secs += (minutes - t->tm_min) * 60;
}
@@ -112,15 +122,15 @@ main(argc, argv)
exit(0);
}
+void
doalarm(secs)
u_int secs;
{
register int bother;
- time_t daytime, time();
+ time_t daytime;
int pid;
- char *ctime();
- if (pid = fork()) {
+ if ((pid = fork())) {
(void)time(&daytime);
daytime += secs;
printf("Alarm set for %.16s. (pid %d)\n",
@@ -137,7 +147,7 @@ doalarm(secs)
#define MSG2 "\07\07You have to leave in 5 minutes.\n"
if (secs >= FIVEMIN) {
sleep(secs - FIVEMIN);
- if (write(1, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1)
+ if (write(STDOUT_FILENO, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1)
exit(0);
secs = FIVEMIN;
}
@@ -146,22 +156,23 @@ doalarm(secs)
#define MSG3 "\07\07Just one more minute!\n"
if (secs >= ONEMIN) {
sleep(secs - ONEMIN);
- if (write(1, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1)
+ if (write(STDOUT_FILENO, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1)
exit(0);
}
#define MSG4 "\07\07Time to leave!\n"
for (bother = 10; bother--;) {
sleep((u_int)ONEMIN);
- if (write(1, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1)
+ if (write(STDOUT_FILENO, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1)
exit(0);
}
#define MSG5 "\07\07That was the last time I'll tell you. Bye.\n"
- (void)write(1, MSG5, sizeof(MSG5) - 1);
+ (void)write(STDOUT_FILENO, MSG5, sizeof(MSG5) - 1);
exit(0);
}
+void
usage()
{
fprintf(stderr, "usage: leave [[+]hhmm]\n");