From 957af01fc24ef4fb2311431d0af9088575eba002 Mon Sep 17 00:00:00 2001
From: Tristan Riehs <tristan.riehs@bordeaux-inp.fr>
Date: Sat, 11 Nov 2023 21:28:00 +0100
Subject: exit status defined as macros

---
 rpt.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

(limited to 'rpt.c')

diff --git a/rpt.c b/rpt.c
index 65e827d..d6adb31 100644
--- a/rpt.c
+++ b/rpt.c
@@ -15,6 +15,13 @@
 /* Size of the buffer used to clone stdin. */
 #define BUFSIZE 8000
 
+/* Exit status */
+#define EXIT_SUCCESS 0
+#define EXIT_INVALID_ARG 1
+#define EXIT_INVALID_COUNT 2
+#define EXIT_NO_COMMAND 3
+#define EXIT_OTHER 4
+
 /* Clone of stdin.  Used to perform lseek(2) calls between each child
    process. */
 FILE *stdin_clone = NULL;
@@ -80,7 +87,7 @@ exec_child(char **argv)
 		if (status < 0)
 		{
 			perror("lseek");
-			exit(4);
+			exit(EXIT_OTHER);
 		}
 	}
 
@@ -89,7 +96,7 @@ exec_child(char **argv)
 	if (status < 0)
 	{
 		perror("dup2");
-		exit(4);
+		exit(EXIT_OTHER);
 	}
 
 	status = execvp(argv[0], argv);
@@ -97,10 +104,10 @@ exec_child(char **argv)
 	if (status < 0)
 	{
 		perror("execvp");
-		exit(4);
+		exit(EXIT_OTHER);
 	}
 
-	exit(4);
+	exit(EXIT_OTHER);
 }
 
 void
@@ -121,7 +128,7 @@ invoke_cmd(char **argv, void (*handle_error_f)(int status))
 	if (pid < 0)
 	{
 		perror("fork");
-		exit(4);
+		exit(EXIT_OTHER);
 	}
 
 	if (pid == 0)
@@ -150,7 +157,7 @@ copy_stdin()
 	if (!stdin_clone)
 	{
 		perror("tmpfile");
-		exit(1);
+		exit(EXIT_OTHER);
 	}
 
 	clone_fd = fileno(stdin_clone);
@@ -165,7 +172,7 @@ copy_stdin()
 	{
 		fclose(stdin_clone);
 		perror("read/write");
-		exit(1);
+		exit(EXIT_OTHER);
 	}
 }
 
-- 
cgit v1.2.3