본문 바로가기

개발 언어/C 언어/리눅스 C

[리눅스] 파일 IO 관련 함수들

■ fgetpos

 파일 스트림에서 현재 위치를 구한다

■ fsetpos

 파일 스트림에서 현재 위치를 설정한다

■ ftell

 스트림에서 현재 파일 오프셋을 반환한다

■ rewind

 스트림에서 파일 위치를 재설정한다

■ setvbuf

 스트림을 위한 버퍼링 구성을 설정한다

■ remove

 path 파라미터가 디렉토릭 아니라면 unlink와 같고, 디렉토리이면 rmdir과 같다

■ freopen()

 - 스트림을 다른 파일이나 방식(mode)로 다시 연다

 - 참고 링크 : http://itguru.tistory.com/59


■ int ferror(FILE *stream) 

 에러 확인

■ int feof(FILE *stream)
 스트림의 끝인지 확인
■ void clearerr(FILE *stream)
 마지막 지시자와 에러 지시자 초기화

■ int fileno(FILE *stream)

 파일 스트림을 파일 디스크립터로 전환

■ FILE *fdopen(int fildes, const char *mode);

 디스크림터를 이용하여 파일 스트림 생성

■ int unlink(const char *path)
 링크카운트 감소로 0이면, 파일 제거
■ int link(const char *path1, const char *path2);
■ int symlink(const char *path1, const char *path2);

■ int chdir(const char *path);
 cd명령처럼 path로 이동
■ char *getcwd(char *buf, size_t size);
현재 디렉토리의 이름을 주어진 버퍼에 저장




디렉터리 검색하기


■ DIR *opendir(const char *name)
■ struct dirent *readdir(DIR *dirp)
■ long int telldir(DIR *dirp)
■ void seekdir(DIR *dirp, long int loc)
■ int closedir(DIR *dirp)





메모리맵


■ void *mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)

 - prot

  PROT_READ: The segment can be read
  PROT_WRITE: The segment can be written
  PROT_EXEC: The segment can be executed 
  PROT_NONE: The segment can’t be accessed
 - flags
  MAP_PRIVATE: The segment is private, changes are local
  MAP_SHARED: The segment changes are made in the file
  MAP_FIXED: The segment must be at the given address, addr(사용되지않음)

■ int msync(void *addr, size_t len, int flags)
 - flags: 갱신을 수행하는 방법
 MS_ASYNC Perform asynchronous writes
 MS_SYNC Perform synchronous writes
 MS_INVALIDATE Read data back in from the file

■ int munmap(void *addr, size_t len)