Date: Wed, 18 Jul 2001 16:31:51 -0400 From: David Hill <david@phobia.ms> To: current@freebsd.org Subject: leave patch Message-ID: <20010718163151.5c8f9d42.david@phobia.ms>
next in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] Hello - This leave patche gets rid of white space before the input, and after the +, if there is one. I also moved the #define's to the top of the source file, and change 1 to STDOUT_FILENO. The patch is included with this email, and is available online at http://www.phobia.ms/patches/leave.c.18072001.patch Thanks - David [-- Attachment #2 --] --- /usr/src/usr.bin/leave/leave.c.orig Wed Jul 18 16:10:27 2001 +++ /usr/src/usr.bin/leave/leave.c Wed Jul 18 16:23:54 2001 @@ -52,6 +52,14 @@ #include <time.h> #include <unistd.h> +#define FIVEMIN (5 * 60) +#define ONEMIN (60) +#define MSG1 "When do you have to leave? " +#define MSG2 "\07\07You have to leave in 5 minutes.\n" +#define MSG3 "\07\07Just one more minute!\n" +#define MSG4 "\07\07Time to leave!\n" +#define MSG5 "\07\07That was the last time I'll tell you. Bye.\n" + void doalarm __P((u_int)); static void usage __P((void)); @@ -79,11 +87,12 @@ warn("setlocale"); 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); + while (isspace(*cp)) cp++ + ; } else if (argc > 2) usage(); else @@ -92,6 +101,8 @@ if (*cp == '+') { plusnow = 1; ++cp; + while (isspace(*cp)) cp++ + ; } else plusnow = 0; @@ -161,32 +172,29 @@ * if write fails, we've lost the terminal through someone else * causing a vhangup by logging in. */ -#define FIVEMIN (5 * 60) -#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; } -#define ONEMIN (60) -#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); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010718163151.5c8f9d42.david>
