출처 : 아주대학교 시스템 소프트웨어 보안 강의자료
/*
* 공부한거 정리하는거라 틀린게 있을 수도 있어요...
* 내용에 틀린게 있으면 알려주세요!!
*/
파일 핸들링에 자주 사용하는 함수들을 정리해봤습니다.
1. open : 프로세스에서 파일을 사용할 수 있도록 파일을 불러오는 함수
파일 원형 | int open(const char *pathname, int flag, /* mode_t mode */ ) |
헤더 | fcntl.h |
반환 | 파일 디스크립터 값을 반환 실패시 -1을 반환 |
인수 설명 |
const char *pathname : 파일의 경로 및 이름 |
2. read : 파일에서 데이터를 읽어오는 함수
파일 원형 | ssize_t read(int filedes, void *buff, size_t nbytes ) |
헤더 | unistd.h |
반환 | 읽어온 데이터의 바이트 수 실패시 -1 |
인수 설명 |
int filedes : 읽을 파일의 디스크립터 |
예제 | https://github.com/jaduwvad/SystemSoftwareSecurity/blob/master/process/readwrite.c |
3. write : 파일에 데이터를 작성하는 함수
파일 원형 | ssize_t write(int filedes, const void *buff, size_t nbytes); |
헤더 | unistd.h |
반환 | 파일에 작성한 데이터의 바이트 수 실패시 -1 |
인수 설명 |
int filedes : 데이터를 작성할 파일의 디스크립터 |
예제 | https://github.com/jaduwvad/SystemSoftwareSecurity/blob/master/process/readwrite.c |
4. fcntl : 명령어를 통해 열려있는 파일의 특성을 변경하는 함수
파일 원형 | int fcntl(int filedes, int cmd, /* int arg */) |
헤더 | fcntl.h |
반환 | -1이 아닌 값, cmd에 따라 다름 실패시 -1 |
인수 설명 |
int filedes : 명령어를 실행할 대상 파일의 디스크립터 |
예제 | https://github.com/jaduwvad/SystemSoftwareSecurity/blob/master/process/fcntl.c |
5. lstat : 파일에 대한 정보를 가진 stat구조체를 가져오는 함수
함수 원형 | int lstat(const char *filename, struct stat *buf) |
헤더 | sys/stat.h |
반환 | 성공시 0 실패시 -1 |
인수 설명 |
const char *filename : 정보를 가져올 파일 이름 struct stat { |
예제 | https://github.com/jaduwvad/SystemSoftwareSecurity/blob/master/process/sh_file_info.c |
'개발 > 리눅스 프로그래밍' 카테고리의 다른 글
localtime() 사용 시 유의사항 (0) | 2020.01.12 |
---|---|
mariadb-connector 라이브러리 내부 버그 (0) | 2020.01.07 |
좀비 프로세스 방지 (0) | 2019.07.18 |
유닉스 파일 시스템2 (0) | 2019.07.17 |
유닉스 파일 시스템 (0) | 2019.07.17 |