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 /myfind/simple_ls | |
Diffstat (limited to 'myfind/simple_ls')
| -rw-r--r-- | myfind/simple_ls/Makefile | 15 | ||||
| -rw-r--r-- | myfind/simple_ls/simple_ls.c | 41 |
2 files changed, 56 insertions, 0 deletions
diff --git a/myfind/simple_ls/Makefile b/myfind/simple_ls/Makefile new file mode 100644 index 0000000..49af11b --- /dev/null +++ b/myfind/simple_ls/Makefile @@ -0,0 +1,15 @@ +CC = gcc +CFLAGS = -std=c99 -pedantic -Werror -Wall -Wextra -Wvla + +SRC = simple_ls.c +OBJ = $(SRC:.c=.o) + +all: $(OBJ) + $(CC) -o simple_ls $(OBJ) + +$(OBJ): $(SRC) + +.PHONY: clean + +clean : + $(RM) $(OBJ) simple_ls diff --git a/myfind/simple_ls/simple_ls.c b/myfind/simple_ls/simple_ls.c new file mode 100644 index 0000000..084072d --- /dev/null +++ b/myfind/simple_ls/simple_ls.c @@ -0,0 +1,41 @@ +#include <dirent.h> +#include <stdio.h> + +int main(int argc, char **argv) +{ + if (argc > 2) + return 1; + + DIR *d; + if (argc == 1) + { + d = opendir("."); + if (!d) + { + fprintf(stderr, "simple_ls: .: No such file or directory\n"); + return 1; + } + } + else + { + d = opendir(argv[1]); + if (!d) + { + fprintf(stderr, "simple_ls: %s: No such file or directory\n", + argv[1]); + return 1; + } + } + + struct dirent *dir; + while ((dir = readdir(d))) + { + if (dir->d_name[0] != '.') + printf("%s\n", dir->d_name); + } + + if (closedir(d)) + return 1; + + return 0; +} |
