From ed0851eecae6e6342bf8479fe0dfe92b8ab274a4 Mon Sep 17 00:00:00 2001 From: sun Date: Fri, 26 Sep 2025 19:15:23 +0200 Subject: [PATCH] Add main.c --- main.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 main.c diff --git a/main.c b/main.c new file mode 100644 index 0000000..ac1c748 --- /dev/null +++ b/main.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include +#include + +int main(void) { + char buf[256]; + char *args[64]; + + while (1) { + printf("%s ", getuid() ? "$" : "#"); + fflush(stdout); + + if (!fgets(buf, sizeof(buf), stdin)) break; + buf[strcspn(buf, "\n")] = 0; + if (!buf[0]) continue; + if (!strcmp(buf, "exit")) break; + + int i = 0; + char *tok = strtok(buf, " "); + while (tok && i < 63) args[i++] = tok, tok = strtok(NULL, " "); + args[i] = NULL; + + if (fork() == 0) execvp(args[0], args), perror("exec"), exit(1); + else wait(NULL); + } +}