파일 종류 검색

---------------------------

S_IFMT : 0xF000 : st_mode 값에서 파일의 종류를 정의한 부분을 가져옴 

S_FIFO : 0x1000 : FIFO 파일

S_IFCHR : 0x2000 : 문자 장치 특수 파일

S_IFDIR : 0x4000 : 디렉토리 

S_IFBLK : 0x6000 : 블록 장치 특수 파일

S_IFREG : 0x8000 : 일반 파일

S_IFLNK : 0xA000 : 심볼릭 링크 파일

---------------------------------------------------------------

# include <stdio.h>

# include <sys/stat.h>


int main(void) {

struct stat buf; 

int kind;


stat("s_dir", &buf);

printf("mode => (16진수 => %x) \n", (unsigned int)buf.st_mode);


kind = buf.st_mode & S_IFMT;

printf("kind => %x\n", kind);


switch(kind) {

case S_IFDIR: // IF DIR 

printf ("s_dir : directory \n");

break;

case S_IFREG: // IF REG

printf ("s_dir : Regular file \n");

break;

case S_IFLNK: // IF LNK 

printf ("s_dir : symbolic link file \n");

break;

}


return 0;

}



'System programming' 카테고리의 다른 글

시스템 프로그래밍_01  (0) 2018.03.09
시스템 프로그래밍  (0) 2018.03.07
strcpy  (0) 2017.11.08
시스템 프로그래밍_1  (0) 2017.10.09