Most file I/O on a UNIX system can be preformed using only five functions: open, read, write, lseek, and close.

File Descriptors

open, openat 함수

파일을 열기 위해 이 함수들을 사용한다.

#include <fcntl.h>

int open(const char *path, int oflag, ... /* mode_t mode */ );
int openat(int fd, const char *path, int oflag, ... /* mode_t mode */ );

/* Both return: file descriptor if OK, -1 on error */

openat 함수의 의의

openat을 비롯한 *at 함수들은 POSIX.1 표준에 비교적 최근 반영되었다. 이 함수들은 기존의 POSIX 함수들의 다음과 같은 문제를 해결할 수 있었다.

  1. 기존에는 작업 디렉토리 외에는 상대경로를 지정할 수 없었다. 같은 프로세스의 모든 스레드는 같은 작업 디렉토리를 공유하므로, 여러 스레드가 동시에 다른 디렉토리에서 작업하기 어렵다.