Linux/Embedded

open 함수

Hans_S_92 2023. 4. 25. 11:48

간단 설명

     open() 함수는 pathname에 의한 특정한 파일을 오픈하는 시스템 콜이다. 만약이 파일이 존재하지 않는다면 특정 옵션을 사용하여 파일을 만들어 시스템 콜이 가능하다. 

 

NAME
       open, openat, creat - open and possibly create a file

SYNOPSIS
       #include <sys/types.h>
       #include <sys/stat.h>
       #include <fcntl.h>

       int open(const char *pathname, int flags);
       int open(const char *pathname, int flags, mode_t mode);

 

       int creat(const char *pathname, mode_t mode);

       int openat(int dirfd, const char *pathname, int flags);
       int openat(int dirfd, const char *pathname, int flags, mode_t mode);

 

RETURN VALUE
       open(), openat(), and creat() return the new file descriptor, or -1 if an error occurred (in which case, errno is set appropriately).

 

FLAG

 flags 설명 
 O_RDONLY  읽기 전용
 O_WRONLY  쓰기 전용
 O_RDWR  읽기 , 쓰기 모두
 O_CREAT  파일없을 경우 파일 생성
 O_EXCL  파일 존재시 error 리턴

 

MODE

 mode 설명 
 S_IRWXU  00700 / 파일소유자에게 읽기,쓰기,실행권한 부여 
 S_IRUSR   00400 / 사용자에게 읽기 권한 부여
 S_IWUSR  00200 / 사용자에게 쓰기 권한 부여
 S_IXUSR  00100 / 사용자에게 실행 권한 부여
 S_IRWXG  00070 / 그룹에게 읽기,쓰기,실행권한 부여
 S_IRGRP  00040 / 그룹에게 읽기권한 부여
 S_IWGRP  00020 / 그룹에게 쓰기권한 부여
 S_IXGRP  00010 / 그룹에게 실행권한 부여
 S_IRWXO  00007 / 기타 사용자에게 읽기,쓰기,실행권한 부여
 S_IROTH  00004 / 기타 사용자에게 읽기권한 부여
 S_IWOTH  00002 / 기타 사용자에게 쓰기권한 부여
 S_IXOTH  00001 / 기타 사용자에게 실행권한 부여

'Linux > Embedded' 카테고리의 다른 글

fork() function.  (0) 2023.04.26
내가 사용하는 .vimrc 옵션  (0) 2023.04.26
Yocto Project Poky Compile & Execute  (0) 2023.03.13
Vim에서 키패드 숫자입력  (0) 2022.05.02
Ubuntu 메인보드 확인 명령어  (0) 2022.05.02