summary refs log tree commit diff
path: root/progs
diff options
context:
space:
mode:
Diffstat (limited to 'progs')
-rw-r--r--progs/shel/shel.c42
-rw-r--r--progs/touch/touch.c13
2 files changed, 55 insertions, 0 deletions
diff --git a/progs/shel/shel.c b/progs/shel/shel.c
new file mode 100644
index 0000000..f375250
--- /dev/null
+++ b/progs/shel/shel.c
@@ -0,0 +1,42 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <stdbool.h>
+#include <string.h>
+
+void parseInput(char *input, char *command, char *argv) {
+    bool reachedArgv = false;
+    char arg[32] = {0};
+    int idx = 0;
+    int argvIdx = 1;
+    
+    for (int i = 0; i < sizeof(input); i++)
+    {
+        if (reachedArgv) {
+            arg[idx] = input[i];
+            idx++;
+            continue;
+        }
+        if (input[i] == ' ') {
+            arg[idx] == '\0';
+            strcpy(command, arg);
+            reachedArgv = true;
+            memset(arg, 0, sizeof(arg));
+            idx++;
+            continue;
+        }
+        arg[idx] = input[i];
+        idx++;
+    }
+    
+}
+
+int main() {
+    char input[255] = {0};
+    char command[128] = {0};
+    char *argv[32] = {0};
+    char *env[32] = {"PATH=/bin"};
+    char path[128] = "/";
+
+    parseInput(input, command, argv);
+}
\ No newline at end of file
diff --git a/progs/touch/touch.c b/progs/touch/touch.c
new file mode 100644
index 0000000..815dae3
--- /dev/null
+++ b/progs/touch/touch.c
@@ -0,0 +1,13 @@
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+
+int main(int argc, char *argv[]) {
+    if (!argv[1]) {
+        write(1, "you IDIOT, you forgot to include the file name, MORON\n", 55);
+        exit(1);
+    }
+    int fd2 = open(argv[1], O_RDWR | O_CREAT, S_IRUSR | S_IRGRP | S_IROTH);
+    exit(0);
+}
\ No newline at end of file