diff --git a/Makefile b/Makefile index b0cd8d5..a9e1d6f 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ CC = gcc -CFLAGS = -g -Wall -Werror -Wextra -Wformat=2 -Wjump-misses-init -Wlogical-op -Wpedantic -Wshadow +CFLAGS = -std=c99 -g -Wall -Werror -Wextra -Wformat=2 -Wjump-misses-init -Wlogical-op -Wpedantic -Wshadow #CFLAGS = -ansi -g -Wall -Werror -Wextra -Wformat=2 -Wjump-misses-init -Wlogical-op -Wpedantic -Wshadow #CFLAGS = -Wall -Werror -Wextra -Wpedantic EXECUTABLE = ls diff --git a/ls.c b/ls.c index 8b0c585..6ca16fb 100644 --- a/ls.c +++ b/ls.c @@ -1,3 +1,4 @@ +#define _POSIX_C_SOURCE 200809L #include #include @@ -8,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -15,6 +17,10 @@ #include #include +#ifndef PATH_MAX +#define PATH_MAX 4096 +#endif + void ls_ent(const char *path); void do_regfile(const char *path, const struct stat *sb); void do_dir(const char *path, const struct stat *sb); @@ -50,28 +56,20 @@ ls_ent(const char *path) if (lstat(path, &sb) == -1) { err(1, "Failed to stat %s", path); } - switch (sb.st_mode & S_IFMT) { - case S_IFREG: + if (S_ISREG(sb.st_mode)) { do_regfile(path, &sb); - break; - case S_IFDIR: + } else if (S_ISDIR(sb.st_mode)) { do_dir(path, &sb); - break; - case S_IFLNK: + } else if (S_ISLNK(sb.st_mode)) { do_symlink(path, &sb); - break; - case S_IFCHR: + } else if (S_ISCHR(sb.st_mode)) { do_char(path, &sb); - break; - case S_IFIFO: + } else if (S_ISFIFO(sb.st_mode)) { do_fifo(path, &sb); - break; - case S_IFSOCK: + } else if (S_ISSOCK(sb.st_mode)) { do_socket(path, &sb); - break; - default: + } else { do_unknown(path, &sb); - break; } } diff --git a/readme.rst b/readme.rst index 00914a8..4c48632 100644 --- a/readme.rst +++ b/readme.rst @@ -4,3 +4,10 @@ ls above was spellchecked by claude3 + +fts() +isatty() +getopt() +strmode() + +c99