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
|
||||
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
|
||||
|
|
28
ls.c
28
ls.c
|
@ -1,3 +1,4 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
@ -8,6 +9,7 @@
|
|||
#include <libgen.h>
|
||||
#include <limits.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -15,6 +17,10 @@
|
|||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,3 +4,10 @@ ls
|
|||
|
||||
|
||||
above was spellchecked by claude3
|
||||
|
||||
fts()
|
||||
isatty()
|
||||
getopt()
|
||||
strmode()
|
||||
|
||||
c99
|
||||
|
|
Loading…
Reference in a new issue