Thumbnail

rani/cscroll.git

Clone URL: https://git.buni.party/rani/cscroll.git

commit 857df465f74ee323c603350e7476725918048500 Author: Raniconduh <clagv.randomgames@gmail.com> Date: Sat Oct 09 19:56:02 2021 +0000 added FILE_SOCK and used switch for file type determination diff --git a/include/dir.h b/include/dir.h index 68ba5a1..123d504 100644 --- a/include/dir.h +++ b/include/dir.h @@ -166 +167 @@ enum file_type_t {   FILE_FIFO,   FILE_LINK,   FILE_BLK, + FILE_SOCK,   FILE_UNKNOWN  };   diff --git a/src/dir.c b/src/dir.c index ea4c4d0..d5d984a 100644 --- a/src/dir.c +++ b/src/dir.c @@ -4912 +4930 @@ int list_dir(char * dir_path) {     strcpy(dir_entry->name, d_name);   - mode_t s = buf->st_mode; - if (S_ISBLK(s) || S_ISCHR(s)) dir_entry->file_type = FILE_BLK; - else if (S_ISDIR(s)) dir_entry->file_type = FILE_DIR; - else if (S_ISFIFO(s)) dir_entry->file_type = FILE_FIFO; - else if (S_ISLNK(s)) dir_entry->file_type = FILE_LINK; - else dir_entry->file_type = FILE_REG; + switch(buf->st_mode & S_IFMT) { + case S_IFBLK: + case S_IFCHR: + dir_entry->file_type = FILE_BLK; + break; + case S_IFSOCK: + dir_entry->file_type = FILE_SOCK; + break; + case S_IFDIR: + dir_entry->file_type = FILE_DIR; + break; + case S_IFLNK: + dir_entry->file_type = FILE_LINK; + break; + case S_IFIFO: + dir_entry->file_type = FILE_FIFO; + break; + case S_IFREG: + dir_entry->file_type = FILE_REG; + break; + default: + dir_entry->file_type = FILE_UNKNOWN; + break; + }   free(buf);     dir_entries[n_dir_entries] = dir_entry;