Skip to content

Commit

Permalink
leave(1): Replace magic exit codes with standard macros
Browse files Browse the repository at this point in the history
Signed-off-by: Faraz Vahedi <[email protected]>
Reviewed by:	oshogbo
MFC after:	1 week
Pull Request:	#1499
  • Loading branch information
kfv authored and oshogbo committed Nov 27, 2024
1 parent 95498a5 commit f7a6cf3
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions usr.bin/leave/leave.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
* SUCH DAMAGE.
*/

#include <err.h>
#include <ctype.h>
#include <err.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -66,7 +66,7 @@ main(int argc, char **argv)
(void)write(STDOUT_FILENO, MSG1, sizeof(MSG1) - 1);
cp = fgets(buf, sizeof(buf), stdin);
if (cp == NULL || *cp == '\n')
exit(0);
exit(EXIT_SUCCESS);
} else if (argc > 2)
usage();
else
Expand Down Expand Up @@ -117,7 +117,7 @@ main(int argc, char **argv)
secs -= now % 60; /* truncate (now + secs) to min */
}
doalarm(secs);
exit(0);
exit(EXIT_SUCCESS);
}

void
Expand All @@ -133,7 +133,7 @@ doalarm(u_int secs)
daytime += secs;
strftime(tb, sizeof(tb), "%+", localtime(&daytime));
printf("Alarm set for %s. (pid %d)\n", tb, pid);
exit(0);
exit(EXIT_SUCCESS);
}
sleep((u_int)2); /* let parent print set message */
if (secs >= 2)
Expand All @@ -148,7 +148,7 @@ doalarm(u_int secs)
if (secs >= FIVEMIN) {
sleep(secs - FIVEMIN);
if (write(STDOUT_FILENO, MSG2, sizeof(MSG2) - 1) != sizeof(MSG2) - 1)
exit(0);
exit(EXIT_SUCCESS);
secs = FIVEMIN;
}

Expand All @@ -157,24 +157,24 @@ doalarm(u_int secs)
if (secs >= ONEMIN) {
sleep(secs - ONEMIN);
if (write(STDOUT_FILENO, MSG3, sizeof(MSG3) - 1) != sizeof(MSG3) - 1)
exit(0);
exit(EXIT_SUCCESS);
}

#define MSG4 "\07\07Time to leave!\n"
for (bother = 10; bother--;) {
sleep((u_int)ONEMIN);
if (write(STDOUT_FILENO, MSG4, sizeof(MSG4) - 1) != sizeof(MSG4) - 1)
exit(0);
exit(EXIT_SUCCESS);
}

#define MSG5 "\07\07That was the last time I'll tell you. Bye.\n"
(void)write(STDOUT_FILENO, MSG5, sizeof(MSG5) - 1);
exit(0);
exit(EXIT_SUCCESS);
}

static void
usage(void)
{
fprintf(stderr, "usage: leave [[+]hhmm]\n");
exit(1);
exit(EXIT_FAILURE);
}

0 comments on commit f7a6cf3

Please sign in to comment.