1 2

[PATCH] Replace EXIT_* constants with integers

Details
Message ID
<20190329154423.952-1-sir@cmpwn.com>
DKIM signature
pass
Download raw message
Patch: +117 -117
---
 builtin/alias.c              |  8 ++++----
 builtin/cd.c                 | 20 ++++++++++----------
 builtin/colon.c              |  2 +-
 builtin/dot.c                | 14 +++++++-------
 builtin/eval.c               |  6 +++---
 builtin/exit.c               |  6 +++---
 builtin/export.c             |  8 ++++----
 builtin/false.c              |  2 +-
 builtin/getopts.c            | 12 ++++++------
 builtin/pwd.c                | 10 +++++-----
 builtin/read.c               |  6 +++---
 builtin/set.c                | 16 ++++++++--------
 builtin/shift.c              | 18 +++++++++---------
 builtin/times.c              |  8 ++++----
 builtin/true.c               |  2 +-
 builtin/type.c               |  6 +++---
 builtin/ulimit.c             | 14 +++++++-------
 builtin/umask.c              |  8 ++++----
 builtin/unalias.c            | 10 +++++-----
 builtin/unset.c              |  8 ++++----
 builtin/unspecified.c        |  4 ++--
 highlight.c                  | 10 +++++-----
 main.c                       | 12 ++++++------
 shell/redir.c                |  4 ++--
 shell/shell.c                |  2 +-
 shell/task/assignment.c      |  4 ++--
 shell/task/async.c           |  4 ++--
 shell/task/command_process.c |  4 ++--
 shell/task/task.c            |  2 +-
 shell/task/word.c            |  4 ++--
 30 files changed, 117 insertions(+), 117 deletions(-)

diff --git a/builtin/alias.c b/builtin/alias.c
index 1a5e2a7..d20ea59 100644
--- a/builtin/alias.c
@@ -21,12 +21,12 @@ int builtin_alias(struct mrsh_state *state, int argc, char *argv[]) {
 	if (mrsh_getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "alias: unknown option -- %c\n", mrsh_optopt);
 		fprintf(stderr, alias_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	if (mrsh_optind == argc) {
 		mrsh_hashtable_for_each(&state->aliases, print_alias_iterator, NULL);
-		return EXIT_SUCCESS;
+		return 0;
 	}
 
 	for (int i = mrsh_optind; i < argc; ++i) {
@@ -42,7 +42,7 @@ int builtin_alias(struct mrsh_state *state, int argc, char *argv[]) {
 			const char *value = mrsh_hashtable_get(&state->aliases, alias);
 			if (value == NULL) {
 				fprintf(stderr, "%s: %s not found\n", argv[0], alias);
-				return EXIT_FAILURE;
+				return 1;
 			}
 
 			printf("%s=", alias);
@@ -51,5 +51,5 @@ int builtin_alias(struct mrsh_state *state, int argc, char *argv[]) {
 		}
 	}
 
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/cd.c b/builtin/cd.c
index e977298..85a1c93 100644
--- a/builtin/cd.c
@@ -17,17 +17,17 @@ static int cd(struct mrsh_state *state, const char *path) {
 	if (chdir(path) != 0) {
 		// TODO make better error messages
 		fprintf(stderr, "cd: %s\n", strerror(errno));
-		return EXIT_FAILURE;
+		return 1;
 	}
 	char cwd[PATH_MAX];
 	if (getcwd(cwd, PATH_MAX) == NULL) {
 		fprintf(stderr, "cd: Cannot set new PWD as the path "
 			"is too long\n");
-		return EXIT_FAILURE;
+		return 1;
 	}
 	mrsh_env_set(state, "OLDPWD", oldPWD, MRSH_VAR_ATTRIB_NONE);
 	mrsh_env_set(state, "PWD", cwd, MRSH_VAR_ATTRIB_EXPORT);
-	return EXIT_SUCCESS;
+	return 0;
 }
 
 static int isdir(char *path) {
@@ -45,11 +45,11 @@ int builtin_cd(struct mrsh_state *state, int argc, char *argv[]) {
 		case 'P':
 			// TODO implement `-L` and `-P`
 			fprintf(stderr, "cd: `-L` and `-P` not yet implemented\n");
-			return EXIT_FAILURE;
+			return 1;
 		default:
 			fprintf(stderr, "cd: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, cd_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 
@@ -60,7 +60,7 @@ int builtin_cd(struct mrsh_state *state, int argc, char *argv[]) {
 		}
 		fprintf(stderr, "cd: No arguments were given and $HOME "
 			"is not defined.\n");
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	char *curpath = argv[mrsh_optind];
@@ -71,22 +71,22 @@ int builtin_cd(struct mrsh_state *state, int argc, char *argv[]) {
 		const char *pwd = mrsh_env_get(state, "PWD", NULL);
 		if (!pwd) {
 			fprintf(stderr, "cd: PWD is not set\n");
-			return EXIT_FAILURE;
+			return 1;
 		}
 		if (!oldpwd) {
 			fprintf(stderr, "cd: OLDPWD is not set\n");
-			return EXIT_FAILURE;
+			return 1;
 		}
 		if (chdir(oldpwd) != 0) {
 			fprintf(stderr, "cd: %s\n", strerror(errno));
-			return EXIT_FAILURE;
+			return 1;
 		}
 		char *_pwd = strdup(pwd);
 		puts(oldpwd);
 		mrsh_env_set(state, "PWD", oldpwd, MRSH_VAR_ATTRIB_EXPORT);
 		mrsh_env_set(state, "OLDPWD", _pwd, MRSH_VAR_ATTRIB_NONE);
 		free(_pwd);
-		return EXIT_SUCCESS;
+		return 0;
 	}
 	// $CDPATH
 	if (curpath[0] != '/' && strncmp(curpath, "./", 2) != 0 &&
diff --git a/builtin/colon.c b/builtin/colon.c
index adad537..03796b0 100644
--- a/builtin/colon.c
@@ -3,5 +3,5 @@
 #include "builtin.h"
 
 int builtin_colon(struct mrsh_state *state, int argc, char *argv[]) {
-	return EXIT_SUCCESS; // This builtin does not do anything
+	return 0; // This builtin does not do anything
 }
diff --git a/builtin/dot.c b/builtin/dot.c
index 8a6c560..b5f6bd5 100644
--- a/builtin/dot.c
@@ -16,16 +16,16 @@ static const char source_usage[] = "usage: . <path>\n";
 int builtin_dot(struct mrsh_state *state, int argc, char *argv[]) {
 	if (argc != 2) {
 		fprintf(stderr, source_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	const char *path = expand_path(state, argv[1], false);
 	if (!path) {
 		fprintf(stderr, "%s: not found\n", argv[1]);
 		if (!state->interactive) {
-			state->exit = EXIT_FAILURE;
+			state->exit = 1;
 		}
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	int fd = open(path, O_RDONLY | O_CLOEXEC);
@@ -45,9 +45,9 @@ int builtin_dot(struct mrsh_state *state, int argc, char *argv[]) {
 		if (err_msg != NULL) {
 			fprintf(stderr, "%s %d:%d: %s\n",
 				argv[1], err_pos.line, err_pos.column, err_msg);
-			ret = EXIT_FAILURE;
+			ret = 1;
 		} else {
-			ret = EXIT_SUCCESS;
+			ret = 0;
 		}
 	} else {
 		ret = mrsh_run_program(state, program);
@@ -60,7 +60,7 @@ int builtin_dot(struct mrsh_state *state, int argc, char *argv[]) {
 
 error:
 	if (!state->interactive) {
-		state->exit = EXIT_FAILURE;
+		state->exit = 1;
 	}
-	return EXIT_FAILURE;
+	return 1;
 }
diff --git a/builtin/eval.c b/builtin/eval.c
index 9edf2ab..509b994 100644
--- a/builtin/eval.c
@@ -15,7 +15,7 @@ static const char eval_usage[] = "usage: eval [cmds...]\n";
 int builtin_eval(struct mrsh_state *state, int argc, char *argv[]) {
 	if (argc == 1) {
 		fprintf(stderr, eval_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	struct mrsh_buffer buf = {0};
@@ -38,9 +38,9 @@ int builtin_eval(struct mrsh_state *state, int argc, char *argv[]) {
 		if (err_msg != NULL) {
 			fprintf(stderr, "%s %d:%d: %s\n",
 				argv[1], err_pos.line, err_pos.column, err_msg);
-			ret = EXIT_FAILURE;
+			ret = 1;
 		} else {
-			ret = EXIT_SUCCESS;
+			ret = 0;
 		}
 	} else {
 		ret = mrsh_run_program(state, program);
diff --git a/builtin/exit.c b/builtin/exit.c
index 4d59b93..7f6bb5d 100644
--- a/builtin/exit.c
@@ -9,7 +9,7 @@ static const char exit_usage[] = "usage: exit [n]\n";
 int builtin_exit(struct mrsh_state *state, int argc, char *argv[]) {
 	if (argc > 2) {
 		fprintf(stderr, exit_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	int status = 0;
@@ -20,11 +20,11 @@ int builtin_exit(struct mrsh_state *state, int argc, char *argv[]) {
 		if (endptr[0] != '\0' || errno != 0 ||
 				status_long < 0 || status_long > 255) {
 			fprintf(stderr, exit_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 		status = (int)status_long;
 	}
 
 	state->exit = status;
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/export.c b/builtin/export.c
index 7843a2b..a48ddc1 100644
--- a/builtin/export.c
@@ -15,7 +15,7 @@ int builtin_export(struct mrsh_state *state, int argc, char *argv[]) {
 
 	if (argc < 2) {
 		fprintf(stderr, export_usage, argv[0]);
-		return EXIT_FAILURE;
+		return 1;
 	} else if (argc == 2 && strcmp(argv[1], "-p") == 0) {
 		size_t count;
 		struct mrsh_collect_var *vars = mrsh_collect_vars(
@@ -26,7 +26,7 @@ int builtin_export(struct mrsh_state *state, int argc, char *argv[]) {
 			printf("\n");
 		}
 		free(vars);
-		return EXIT_SUCCESS;
+		return 0;
 	}
 
 	for (int i = 1; i < argc; ++i) {
@@ -50,11 +50,11 @@ int builtin_export(struct mrsh_state *state, int argc, char *argv[]) {
 			fprintf(stderr, "%s: cannot modify readonly variable %s\n",
 					argv[0], key);
 			free(key);
-			return EXIT_FAILURE;
+			return 1;
 		}
 		mrsh_env_set(state, key, val, attrib | prev_attribs);
 		free(key);
 	}
 
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/false.c b/builtin/false.c
index d9c3045..26ca80c 100644
--- a/builtin/false.c
@@ -3,5 +3,5 @@
 #include "builtin.h"
 
 int builtin_false(struct mrsh_state *state, int argc, char *argv[]) {
-	return EXIT_FAILURE;
+	return 1;
 }
diff --git a/builtin/getopts.c b/builtin/getopts.c
index 80b8e08..3832b86 100644
--- a/builtin/getopts.c
@@ -16,11 +16,11 @@ int builtin_getopts(struct mrsh_state *state, int argc, char *argv[]) {
 	if (mrsh_getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "getopts: unknown option -- %c\n", mrsh_optopt);
 		fprintf(stderr, getopts_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 	if (mrsh_optind + 2 < argc) {
 		fprintf(stderr, getopts_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	int optc;
@@ -38,13 +38,13 @@ int builtin_getopts(struct mrsh_state *state, int argc, char *argv[]) {
 	const char *optind_str = mrsh_env_get(state, "OPTIND", NULL);
 	if (optind_str == NULL) {
 		fprintf(stderr, "getopts: OPTIND is not defined\n");
-		return EXIT_FAILURE;
+		return 1;
 	}
 	char *endptr;
 	long optind_long = strtol(optind_str, &endptr, 10);
 	if (endptr[0] != '\0' || optind_long <= 0 || optind_long > INT_MAX) {
 		fprintf(stderr, "getopts: OPTIND is not a positive integer\n");
-		return EXIT_FAILURE;
+		return 1;
 	}
 	mrsh_optind = (int)optind_long;
 
@@ -90,7 +90,7 @@ int builtin_getopts(struct mrsh_state *state, int argc, char *argv[]) {
 	mrsh_env_set(state, name, value, MRSH_VAR_ATTRIB_NONE);
 
 	if (opt == -1) {
-		return EXIT_FAILURE;
+		return 1;
 	}
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/pwd.c b/builtin/pwd.c
index 796340d..370cf91 100644
--- a/builtin/pwd.c
@@ -16,23 +16,23 @@ int builtin_pwd(struct mrsh_state *state, int argc, char *argv[]) {
 		case 'P':
 			// TODO implement `-L` and `-P`
 			fprintf(stderr, "pwd: `-L` and `-P` not yet implemented\n");
-			return EXIT_FAILURE;
+			return 1;
 		default:
 			fprintf(stderr, "pwd: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, pwd_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 	if (mrsh_optind < argc) {
 		fprintf(stderr, pwd_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	const char *pwd = mrsh_env_get(state, "PWD", NULL);
 	if (pwd == NULL) {
 		fprintf(stderr, "pwd: Cannot return current directory as PWD was unset\n");
-		return EXIT_FAILURE;
+		return 1;
 	}
 	puts(pwd);
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/read.c b/builtin/read.c
index b79471f..40bea4f 100644
--- a/builtin/read.c
@@ -24,12 +24,12 @@ int builtin_read(struct mrsh_state *state, int argc, char *argv[]) {
 		default:
 			fprintf(stderr, "read: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, read_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 	if (mrsh_optind == argc) {
 		fprintf(stderr, read_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	struct mrsh_buffer buf = {0};
@@ -89,5 +89,5 @@ int builtin_read(struct mrsh_state *state, int argc, char *argv[]) {
 		free(fields.data[i]);
 	}
 	mrsh_array_finish(&fields);
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/set.c b/builtin/set.c
index b19747e..5e4ef50 100644
--- a/builtin/set.c
@@ -95,7 +95,7 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 			printf("\n");
 		}
 		free(vars);
-		return EXIT_SUCCESS;
+		return 0;
 	}
 
 	bool force_positional = false;
@@ -111,19 +111,19 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 		}
 		if (argv[i][1] == '\0') {
 			fprintf(stderr, set_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 		const struct option_map *option;
 		switch (argv[i][1]) {
 		case 'o':
 			if (i + 1 == argc) {
 				fprintf(stderr, set_usage);
-				return EXIT_FAILURE;
+				return 1;
 			}
 			option = find_long_option(argv[i + 1]);
 			if (!option) {
 				fprintf(stderr, set_usage);
-				return EXIT_FAILURE;
+				return 1;
 			}
 			if (argv[i][0] == '-') {
 				state->options |= option->value;
@@ -135,7 +135,7 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 		case 'c':
 			if (init_args == NULL) {
 				fprintf(stderr, set_usage);
-				return EXIT_FAILURE;
+				return 1;
 			}
 			state->interactive = false;
 			init_args->command_str = argv[i + 1];
@@ -144,7 +144,7 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 		case 's':
 			if (init_args == NULL) {
 				fprintf(stderr, set_usage);
-				return EXIT_FAILURE;
+				return 1;
 			}
 			init_args->command_str = NULL;
 			init_args->command_file = NULL;
@@ -154,7 +154,7 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 				option = find_option(argv[i][j]);
 				if (!option) {
 					fprintf(stderr, set_usage);
-					return EXIT_FAILURE;
+					return 1;
 				}
 				if (argv[i][0] == '-') {
 					state->options |= option->value;
@@ -187,7 +187,7 @@ static int set(struct mrsh_state *state, struct mrsh_init_args *init_args,
 		state->args->argv = argv_dup(strdup(argv[0]), 1, argv);
 	}
 
-	return EXIT_SUCCESS;
+	return 0;
 }
 
 int builtin_set(struct mrsh_state *state, int argc, char *argv[]) {
diff --git a/builtin/shift.c b/builtin/shift.c
index 6b5b28e..8a9ce47 100644
--- a/builtin/shift.c
@@ -9,7 +9,7 @@ static const char shift_usage[] = "usage: shift [n]\n";
 int builtin_shift(struct mrsh_state *state, int argc, char *argv[]) {
 	if (argc > 2) {
 		fprintf(stderr, shift_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 	int n = 1;
 	if (argc == 2) {
@@ -19,26 +19,26 @@ int builtin_shift(struct mrsh_state *state, int argc, char *argv[]) {
 		if (*endptr != '\0' || errno != 0) {
 			fprintf(stderr, shift_usage);
 			if (!state->interactive) {
-				state->exit = EXIT_FAILURE;
+				state->exit = 1;
 			}
-			return EXIT_FAILURE;
+			return 1;
 		}
 		n = (int)n_long;
 	}
 	if (n == 0) {
-		return EXIT_SUCCESS;
+		return 0;
 	} else if (n < 1) {
 		fprintf(stderr, "shift: [n] must be positive\n");
 		if (!state->interactive) {
-			state->exit = EXIT_FAILURE;
+			state->exit = 1;
 		}
-		return EXIT_FAILURE;
+		return 1;
 	} else if (n > state->args->argc - 1) {
 		fprintf(stderr, "shift: [n] must be less than $#\n");
 		if (!state->interactive) {
-			state->exit = EXIT_FAILURE;
+			state->exit = 1;
 		}
-		return EXIT_FAILURE;
+		return 1;
 	}
 	for (int i = 1, j = n + 1; j < state->args->argc; ++i, ++j) {
 		if (j <= state->args->argc - n) {
@@ -48,5 +48,5 @@ int builtin_shift(struct mrsh_state *state, int argc, char *argv[]) {
 		}
 	}
 	state->args->argc -= n;
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/times.c b/builtin/times.c
index 9bafab8..be2ee12 100644
--- a/builtin/times.c
@@ -12,19 +12,19 @@ static const char times_usage[] = "usage: times\n";
 int builtin_times(struct mrsh_state *state, int argc, char *argv[]) {
 	if (argc > 1) {
 		fprintf(stderr, times_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	struct tms buf;
 	long clk_tck = sysconf(_SC_CLK_TCK);
 	if (clk_tck == -1) {
 		fprintf(stderr, "sysconf error: %s", strerror(errno));
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	if (times(&buf) == (clock_t)-1) {
 		fprintf(stderr, "times error: %s", strerror(errno));
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	printf("%dm%fs %dm%fs\n%dm%fs %dm%fs\n",
@@ -37,5 +37,5 @@ int builtin_times(struct mrsh_state *state, int argc, char *argv[]) {
 			(int)(buf.tms_cstime / clk_tck / 60),
 			((double)buf.tms_cstime) / clk_tck);
 
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/true.c b/builtin/true.c
index 3cdfee6..7552a34 100644
--- a/builtin/true.c
@@ -3,5 +3,5 @@
 #include "builtin.h"
 
 int builtin_true(struct mrsh_state *state, int argc, char *argv[]) {
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/type.c b/builtin/type.c
index 739349d..46939af 100644
--- a/builtin/type.c
@@ -13,11 +13,11 @@ int builtin_type(struct mrsh_state *state, int argc, char *argv[]) {
 	if (mrsh_getopt(argc, argv, ":") != -1) {
 		fprintf(stderr, "type: unknown option -- %c\n", mrsh_optopt);
 		fprintf(stderr, type_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 	if (mrsh_optind == argc) {
 		fprintf(stderr, type_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	bool error = false;
@@ -45,5 +45,5 @@ int builtin_type(struct mrsh_state *state, int argc, char *argv[]) {
 		error = true;
 	}
 
-	return error ? EXIT_FAILURE : EXIT_SUCCESS;
+	return error ? 1 : 0;
 }
diff --git a/builtin/ulimit.c b/builtin/ulimit.c
index a33e880..71a5235 100644
--- a/builtin/ulimit.c
@@ -21,7 +21,7 @@ int builtin_ulimit(struct mrsh_state *state, int argc, char *argv[]) {
 			// Nothing here
 		} else {
 			fprintf(stderr, "%s", ulimit_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 
@@ -32,12 +32,12 @@ int builtin_ulimit(struct mrsh_state *state, int argc, char *argv[]) {
 		long int new_limit = strtol(arg, &endptr, 10);
 		if (errno != 0) {
 			fprintf(stderr, "strtol error: %s\n", strerror(errno));
-			return EXIT_FAILURE;
+			return 1;
 		}
 		if ((endptr == arg) || (endptr[0] != '\0')) {
 			fprintf(stderr, "ulimit error: Invalid argument: %s\n",
 				arg);
-			return EXIT_FAILURE;
+			return 1;
 		}
 		struct rlimit new = {
 			.rlim_cur = new_limit * 512,
@@ -45,13 +45,13 @@ int builtin_ulimit(struct mrsh_state *state, int argc, char *argv[]) {
 		};
 		if (setrlimit(RLIMIT_FSIZE, &new) != 0) {
 			fprintf(stderr, "setrlimit error: %s\n", strerror(errno));
-			return EXIT_FAILURE;
+			return 1;
 		}
 	} else if (mrsh_optind == argc) {
 		struct rlimit old = { 0 };
 		if (getrlimit(RLIMIT_FSIZE, &old) != 0) {
 			fprintf(stderr, "getrlimit error: %s\n", strerror(errno));
-			return EXIT_FAILURE;
+			return 1;
 		}
 		if (old.rlim_max == RLIM_INFINITY) {
 			printf("unlimited\n");
@@ -60,8 +60,8 @@ int builtin_ulimit(struct mrsh_state *state, int argc, char *argv[]) {
 		}
 	} else {
 		fprintf(stderr, "%s", ulimit_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/umask.c b/builtin/umask.c
index 777ddb0..9bfa90e 100644
--- a/builtin/umask.c
@@ -174,7 +174,7 @@ int builtin_umask(struct mrsh_state *state, int argc, char *argv[]) {
 		default:
 			fprintf(stderr, "Unknown option -- '%c'\n", mrsh_optopt);
 			fprintf(stderr, umask_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 
@@ -187,7 +187,7 @@ int builtin_umask(struct mrsh_state *state, int argc, char *argv[]) {
 			printf("%04o\n", mode);
 		}
 
-		return EXIT_SUCCESS;
+		return 0;
 	}
 
 	char *endptr;
@@ -196,10 +196,10 @@ int builtin_umask(struct mrsh_state *state, int argc, char *argv[]) {
 	if (*endptr != '\0') {
 		if (!umask_mode(&mode, argv[mrsh_optind])) {
 			fprintf(stderr, umask_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 
 	umask(mode);
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/unalias.c b/builtin/unalias.c
index 8590824..fe25bfb 100644
--- a/builtin/unalias.c
@@ -25,26 +25,26 @@ int builtin_unalias(struct mrsh_state *state, int argc, char *argv[]) {
 		default:
 			fprintf(stderr, "unalias: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, unalias_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 
 	if (all) {
 		if (mrsh_optind < argc) {
 			fprintf(stderr, unalias_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 		mrsh_hashtable_for_each(&state->aliases, delete_alias_iterator, &state->aliases);
-		return EXIT_SUCCESS;
+		return 0;
 	}
 
 	if (mrsh_optind == argc) {
 		fprintf(stderr, unalias_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	for (int i = mrsh_optind; i < argc; ++i) {
 		free(mrsh_hashtable_del(&state->aliases, argv[i]));
 	}
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/unset.c b/builtin/unset.c
index b522624..d6b0363 100644
--- a/builtin/unset.c
@@ -24,12 +24,12 @@ int builtin_unset(struct mrsh_state *state, int argc, char *argv[]) {
 		default:
 			fprintf(stderr, "unset: unknown option -- %c\n", mrsh_optopt);
 			fprintf(stderr, unset_usage);
-			return EXIT_FAILURE;
+			return 1;
 		}
 	}
 	if (mrsh_optind >= argc) {
 		fprintf(stderr, unset_usage);
-		return EXIT_FAILURE;
+		return 1;
 	}
 	for (int i = mrsh_optind; i < argc; ++i) {
 		if (!funcs) {
@@ -38,7 +38,7 @@ int builtin_unset(struct mrsh_state *state, int argc, char *argv[]) {
 				if ((prev_attribs & MRSH_VAR_ATTRIB_READONLY)) {
 					fprintf(stderr,
 						"unset: cannot modify readonly variable %s\n", argv[i]);
-					return EXIT_FAILURE;
+					return 1;
 				}
 				mrsh_env_unset(state, argv[i]);
 			}
@@ -48,5 +48,5 @@ int builtin_unset(struct mrsh_state *state, int argc, char *argv[]) {
 			mrsh_function_destroy(oldfn);
 		}
 	}
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/builtin/unspecified.c b/builtin/unspecified.c
index c52aefd..1c64d98 100644
--- a/builtin/unspecified.c
@@ -11,8 +11,8 @@ int builtin_unspecified(struct mrsh_state *state, int argc, char *argv[]) {
 	} else {
 		fprintf(stderr, "%s: The behavior of this command is undefined. "
 				"This is an error in your script. Aborting.\n", argv[0]);
-		state->exit = EXIT_FAILURE;
+		state->exit = 1;
 	}
 
-	return EXIT_FAILURE;
+	return 1;
 }
diff --git a/highlight.c b/highlight.c
index a146381..dae3b51 100644
--- a/highlight.c
+++ b/highlight.c
@@ -45,7 +45,7 @@ static void highlight(struct highlight_state *state, struct mrsh_position *pos,
 	} else {
 		if (state->fmt_stack_len >= FORMAT_STACK_SIZE) {
 			fprintf(stderr, "format stack overflow\n");
-			exit(EXIT_FAILURE);
+			exit(1);
 		}
 		state->fmt_stack[state->fmt_stack_len] = fmt;
 		++state->fmt_stack_len;
@@ -300,7 +300,7 @@ int main(int argc, char *argv[]) {
 		ssize_t n_read = read(STDIN_FILENO, dst, READ_SIZE);
 		if (n_read < 0) {
 			fprintf(stderr, "read() failed: %s\n", strerror(errno));
-			return EXIT_FAILURE;
+			return 1;
 		} else if (n_read == 0) {
 			break;
 		}
@@ -313,9 +313,9 @@ int main(int argc, char *argv[]) {
 		const char *err_msg = mrsh_parser_error(parser, NULL);
 		if (err_msg != NULL) {
 			fprintf(stderr, "failed to parse script: %s\n", err_msg);
-			return EXIT_FAILURE;
+			return 1;
 		}
-		return EXIT_SUCCESS;
+		return 0;
 	}
 	mrsh_parser_destroy(parser);
 
@@ -333,5 +333,5 @@ int main(int argc, char *argv[]) {
 	assert(state.fmt_stack_len == 0);
 
 	mrsh_buffer_finish(&buf);
-	return EXIT_SUCCESS;
+	return 0;
 }
diff --git a/main.c b/main.c
index 648d215..eeecc86 100644
--- a/main.c
+++ b/main.c
@@ -21,13 +21,13 @@ int main(int argc, char *argv[]) {
 	mrsh_state_init(&state);
 
 	struct mrsh_init_args init_args = {0};
-	if (mrsh_process_args(&state, &init_args, argc, argv) != EXIT_SUCCESS) {
+	if (mrsh_process_args(&state, &init_args, argc, argv) != 0) {
 		mrsh_state_finish(&state);
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	if (!mrsh_populate_env(&state, environ)) {
-		return EXIT_FAILURE;
+		return 1;
 	}
 
 	if (!(state.options & MRSH_OPT_NOEXEC)) {
@@ -56,7 +56,7 @@ int main(int argc, char *argv[]) {
 				if (fd < 0) {
 					fprintf(stderr, "failed to open %s for reading: %s\n",
 						init_args.command_file, strerror(errno));
-					return EXIT_FAILURE;
+					return 1;
 				}
 			} else {
 				fd = STDIN_FILENO;
@@ -107,7 +107,7 @@ int main(int argc, char *argv[]) {
 				if (state.interactive) {
 					continue;
 				} else {
-					state.exit = EXIT_FAILURE;
+					state.exit = 1;
 					break;
 				}
 			} else if (mrsh_parser_eof(parser)) {
@@ -115,7 +115,7 @@ int main(int argc, char *argv[]) {
 				break;
 			} else {
 				fprintf(stderr, "unknown error\n");
-				state.exit = EXIT_FAILURE;
+				state.exit = 1;
 				break;
 			}
 		} else {
diff --git a/shell/redir.c b/shell/redir.c
index b1e2124..5da0196 100644
--- a/shell/redir.c
+++ b/shell/redir.c
@@ -82,11 +82,11 @@ static int create_here_document_fd(const struct mrsh_array *lines) {
 			ssize_t n = write_here_document_line(fds[1], line, -1);
 			if (n < 0) {
 				close(fds[1]);
-				exit(EXIT_FAILURE);
+				exit(1);
 			}
 		}
 		close(fds[1]);
-		exit(EXIT_SUCCESS);
+		exit(0);
 	}
 
 	close(fds[1]);
diff --git a/shell/shell.c b/shell/shell.c
index 88724c2..d919690 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -84,7 +84,7 @@ void mrsh_env_set(struct mrsh_state *state,
 	struct mrsh_variable *var = calloc(1, sizeof(struct mrsh_variable));
 	if (!var) {
 		fprintf(stderr, "Failed to allocate shell variable");
-		exit(EXIT_FAILURE);
+		exit(1);
 	}
 	var->value = strdup(value);
 	var->attribs = attribs;
diff --git a/shell/task/assignment.c b/shell/task/assignment.c
index df7f728..a9d7f38 100644
--- a/shell/task/assignment.c
+++ b/shell/task/assignment.c
@@ -32,14 +32,14 @@ static int task_assignment_poll(struct task *task, struct context *ctx) {
 			free(new_value);
 			fprintf(stderr, "cannot modify readonly variable %s\n",
 					assign->name);
-			task->status = EXIT_FAILURE;
+			task->status = 1;
 			return TASK_STATUS_ERROR;
 		}
 		mrsh_env_set(ctx->state, assign->name, new_value, attribs);
 		free(new_value);
 	}
 
-	return EXIT_SUCCESS;
+	return 0;
 }
 
 static const struct task_interface task_assignment_impl = {
diff --git a/shell/task/async.c b/shell/task/async.c
index cdcb407..0d2a843 100644
--- a/shell/task/async.c
+++ b/shell/task/async.c
@@ -34,7 +34,7 @@ static int fork_detached(void) {
 		} else if (child_pid == 0) {
 			return 0;
 		} else {
-			exit(EXIT_SUCCESS);
+			exit(0);
 		}
 	} else {
 		if (waitpid(pid, NULL, 0) == -1) {
@@ -60,7 +60,7 @@ static bool task_async_start(struct task *task, struct context *ctx) {
 			if (fd < 0) {
 				fprintf(stderr, "failed to open /dev/null: %s\n",
 					strerror(errno));
-				exit(EXIT_FAILURE);
+				exit(1);
 			}
 			dup2(fd, STDIN_FILENO);
 			close(fd);
diff --git a/shell/task/command_process.c b/shell/task/command_process.c
index a7d0242..bdcc6d2 100644
--- a/shell/task/command_process.c
+++ b/shell/task/command_process.c
@@ -51,7 +51,7 @@ static bool task_process_start(struct task_command *tc, struct context *ctx) {
 			int redir_fd;
 			int fd = process_redir(redir, &redir_fd);
 			if (fd < 0) {
-				exit(EXIT_FAILURE);
+				exit(1);
 			}
 
 			if (fd == redir_fd) {
@@ -62,7 +62,7 @@ static bool task_process_start(struct task_command *tc, struct context *ctx) {
 			if (ret < 0) {
 				fprintf(stderr, "cannot duplicate file descriptor: %s\n",
 					strerror(errno));
-				exit(EXIT_FAILURE);
+				exit(1);
 			}
 			close(fd);
 		}
diff --git a/shell/task/task.c b/shell/task/task.c
index a3d036e..a18f328 100644
--- a/shell/task/task.c
+++ b/shell/task/task.c
@@ -37,7 +37,7 @@ int task_run(struct task *task, struct context *ctx) {
 		int ret = task_poll(task, ctx);
 		if (ret != TASK_STATUS_WAIT) {
 			ctx->state->last_status = ret;
-			if (ret != EXIT_SUCCESS
+			if (ret != 0
 					&& (ctx->state->options & MRSH_OPT_ERREXIT)) {
 				ctx->state->exit = ret;
 			}
diff --git a/shell/task/word.c b/shell/task/word.c
index 1423f34..8cd3c67 100644
--- a/shell/task/word.c
+++ b/shell/task/word.c
@@ -86,7 +86,7 @@ static bool task_word_command_start(struct task_word *tw,
 			mrsh_run_program(ctx->state, wc->program);
 		}
 
-		exit(ctx->state->exit >= 0 ? ctx->state->exit : EXIT_SUCCESS);
+		exit(ctx->state->exit >= 0 ? ctx->state->exit : 0);
 	}
 
 	close(fds[1]);
@@ -227,7 +227,7 @@ static int task_word_poll(struct task *task, struct context *ctx) {
 				struct mrsh_word_string *ws =
 					mrsh_word_string_create(strdup(buf), false);
 				task_word_swap(tw, &ws->word);
-				ret = EXIT_SUCCESS;
+				ret = 0;
 			}
 		}
 		mrsh_arithm_expr_destroy(expr);
-- 
2.21.0
Details
Message ID
<YkEauMk9o8hxfvmIV4xEmqlDKYqwXajvf2bjpdkPWcpEk-C_xY5rAik6USdgkm5eYj8gNJGF28ZKpQlv-N9RKxZnZJi7CvTNZsH67uEH9Z4=@emersion.fr>
In-Reply-To
<20190329154423.952-1-sir@cmpwn.com> (view parent)
DKIM signature
pass
Download raw message
To git.sr.ht:~emersion/mrsh
   a263f96..04937ee  master -> master

Thanks!