diff options
| author | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
|---|---|---|
| committer | Martial Simon <msimon_fr@hotmail.com> | 2025-09-15 01:07:58 +0200 |
| commit | 967be9e750221ab2ab783f95df79bb26d290a45e (patch) | |
| tree | 6802900a5e975f9f68b169f0f503f040056d6952 /42sh/src/builtins/dot.c | |
Diffstat (limited to '42sh/src/builtins/dot.c')
| -rw-r--r-- | 42sh/src/builtins/dot.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/42sh/src/builtins/dot.c b/42sh/src/builtins/dot.c new file mode 100644 index 0000000..6cec097 --- /dev/null +++ b/42sh/src/builtins/dot.c @@ -0,0 +1,43 @@ +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "builtins.h" +#include "utils/env.h" + +int dot(struct string **args) +{ + if (args[0] == NULL) + { + fprintf(stderr, ".: filename argument required\n"); + fflush(stdout); + return 2; + } + if (args[1] != NULL) + { + fprintf(stderr, ".: too many arguments\n"); + fflush(stdout); + return 2; + } + + FILE *file = fopen(args[0]->data, "r"); + if (file == NULL) + { + fprintf(stderr, ".: filename does not exist\n"); + fflush(stdout); + return 1; + } + + char line[1024]; + while (fgets(line, sizeof(line), file)) + { + // TODO : execute file + fputs(line, stdout); + } + fclose(file); + fflush(stdout); + return 0; +} |
