c99
This commit is contained in:
parent
4e11b595a3
commit
5b4facd6fa
3 changed files with 21 additions and 16 deletions
2
Makefile
2
Makefile
|
@ -1,5 +1,5 @@
|
||||||
CC = gcc
|
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 = -ansi -g -Wall -Werror -Wextra -Wformat=2 -Wjump-misses-init -Wlogical-op -Wpedantic -Wshadow
|
||||||
#CFLAGS = -Wall -Werror -Wextra -Wpedantic
|
#CFLAGS = -Wall -Werror -Wextra -Wpedantic
|
||||||
EXECUTABLE = ls
|
EXECUTABLE = ls
|
||||||
|
|
28
ls.c
28
ls.c
|
@ -1,3 +1,4 @@
|
||||||
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -15,6 +17,10 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef PATH_MAX
|
||||||
|
#define PATH_MAX 4096
|
||||||
|
#endif
|
||||||
|
|
||||||
void ls_ent(const char *path);
|
void ls_ent(const char *path);
|
||||||
void do_regfile(const char *path, const struct stat *sb);
|
void do_regfile(const char *path, const struct stat *sb);
|
||||||
void do_dir(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) {
|
if (lstat(path, &sb) == -1) {
|
||||||
err(1, "Failed to stat %s", path);
|
err(1, "Failed to stat %s", path);
|
||||||
}
|
}
|
||||||
switch (sb.st_mode & S_IFMT) {
|
if (S_ISREG(sb.st_mode)) {
|
||||||
case S_IFREG:
|
|
||||||
do_regfile(path, &sb);
|
do_regfile(path, &sb);
|
||||||
break;
|
} else if (S_ISDIR(sb.st_mode)) {
|
||||||
case S_IFDIR:
|
|
||||||
do_dir(path, &sb);
|
do_dir(path, &sb);
|
||||||
break;
|
} else if (S_ISLNK(sb.st_mode)) {
|
||||||
case S_IFLNK:
|
|
||||||
do_symlink(path, &sb);
|
do_symlink(path, &sb);
|
||||||
break;
|
} else if (S_ISCHR(sb.st_mode)) {
|
||||||
case S_IFCHR:
|
|
||||||
do_char(path, &sb);
|
do_char(path, &sb);
|
||||||
break;
|
} else if (S_ISFIFO(sb.st_mode)) {
|
||||||
case S_IFIFO:
|
|
||||||
do_fifo(path, &sb);
|
do_fifo(path, &sb);
|
||||||
break;
|
} else if (S_ISSOCK(sb.st_mode)) {
|
||||||
case S_IFSOCK:
|
|
||||||
do_socket(path, &sb);
|
do_socket(path, &sb);
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
do_unknown(path, &sb);
|
do_unknown(path, &sb);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,3 +4,10 @@ ls
|
||||||
|
|
||||||
|
|
||||||
above was spellchecked by claude3
|
above was spellchecked by claude3
|
||||||
|
|
||||||
|
fts()
|
||||||
|
isatty()
|
||||||
|
getopt()
|
||||||
|
strmode()
|
||||||
|
|
||||||
|
c99
|
||||||
|
|
Loading…
Reference in a new issue