summaryrefslogtreecommitdiff
path: root/42sh/src/builtins/exit.c
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /42sh/src/builtins/exit.c
add: added projectsHEADmain
Diffstat (limited to '42sh/src/builtins/exit.c')
-rw-r--r--42sh/src/builtins/exit.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/42sh/src/builtins/exit.c b/42sh/src/builtins/exit.c
new file mode 100644
index 0000000..943c22f
--- /dev/null
+++ b/42sh/src/builtins/exit.c
@@ -0,0 +1,28 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "builtins.h"
+
+int my_exit(struct string **args)
+{
+ unsigned int res = 0;
+ if (args[0] != NULL)
+ {
+ char *c;
+ long status = strtol(args[0]->data, &c, 10);
+ if (*c != '\0' || status < 0 || status > 255)
+ {
+ fprintf(stderr, "exit: %s: numeric argument required\n",
+ args[0]->data);
+ res = 2;
+ }
+ else
+ {
+ res = (unsigned int)status;
+ }
+ }
+ fflush(stdout);
+ exit(res);
+}