summaryrefslogtreecommitdiff
path: root/myfind/simple_ls/simple_ls.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 /myfind/simple_ls/simple_ls.c
add: added projectsHEADmain
Diffstat (limited to 'myfind/simple_ls/simple_ls.c')
-rw-r--r--myfind/simple_ls/simple_ls.c41
1 files changed, 41 insertions, 0 deletions
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;
+}