aboutsummaryrefslogtreecommitdiffstats
path: root/ls.c
diff options
context:
space:
mode:
authorSquibid <me@zacharyscheiman.com>2023-05-03 22:36:17 -0400
committerSquibid <me@zacharyscheiman.com>2023-05-03 22:36:17 -0400
commit55f5a1d0ba00ad8e15fadc391e4aa3960c9afdb3 (patch)
tree1e4412fe19e1471026a580d427f44730768b3a50 /ls.c
downloadcoreutils-55f5a1d0ba00ad8e15fadc391e4aa3960c9afdb3.tar.gz
coreutils-55f5a1d0ba00ad8e15fadc391e4aa3960c9afdb3.tar.bz2
coreutils-55f5a1d0ba00ad8e15fadc391e4aa3960c9afdb3.zip
inital commit most of the current utils don't work
Diffstat (limited to 'ls.c')
-rw-r--r--ls.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/ls.c b/ls.c
new file mode 100644
index 0000000..630ee4a
--- /dev/null
+++ b/ls.c
@@ -0,0 +1,34 @@
+#include <dirent.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int main(int argc, char *argv[])
+{
+ DIR *d;
+ char *dirs;
+ struct dirent *dir;
+ int hidden = 1;
+ int c;
+
+ while ((c = getopt(argc, argv, "a")) != -1) {
+ switch (c) {
+ case 'a': hidden = 0; break;
+ }
+ }
+
+ if (argc > 0) {
+ for (int i = 1; i < argc; i++) {
+ dirs = argv[i];
+ if ((d = opendir(dirs))) {
+ while ((dir = readdir(d)) != NULL) {
+ if (strncmp(dir->d_name, ".", 1) != 0 && hidden) /* dont print hidden files */
+ printf("%s\n", dir->d_name);
+ else if (!hidden)
+ printf("%s\n", dir->d_name);
+ }
+ closedir(d);
+ }
+ }
+ }
+}