-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.c
More file actions
33 lines (33 loc) · 906 Bytes
/
Copy pathls.c
File metadata and controls
33 lines (33 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include"header.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void lsCommand(){
DIR *dr = opendir(".");
struct dirent *d;
while(NULL != (d=readdir(dr))){
struct stat sb;
if (stat(d->d_name, &sb) == -1) {
perror("stat");
exit(EXIT_FAILURE);
}
switch (sb.st_mode & S_IFMT) {
case S_IFBLK: printf("b"); break;
case S_IFCHR: printf("c"); break;
case S_IFDIR:
//Directory
printf("d"); break;
case S_IFIFO: //FIFO/pipe
printf("p"); break;
case S_IFLNK: //Symbolic Link
printf("sl"); break;
case S_IFREG: //Regular File
printf("f"); break;
case S_IFSOCK: //Socket
printf("s"); break;
default: printf("?"); break;
}
printf("\t%s",d->d_name);
printf("\n");
}
}