DISK I/O [5]
Handling file offset
#include <stdio.h>
int fseek (FILE * stream, long offset, int whence);
long ftell (FILE * stream);
void rewind (FILE *stream);
int fsetpos (FILE * stream, const fpos_t *pos);
int fgetpos (FILE *stream, fpos_t *pos);
stream
offset: 이동시킬 byte의 수 (양수 or 음수)
whnce: 기준 위치 (SEEK_SET, SEEK_CUR, SEEK_END)
pos: offset을 저장 할 (or 하고있는) fpos_t 주소
Return -> Man page 참조
File Pointer <-> File Descriptor
#include <stdio.h>
FILE *fdopen (int fd, const char *mode);
fd: file descriptor
mode: 파일 열기 모드 (fd를 열 때와 같은 종류이어야 함)
return File pointer | NULL = fail to open
int fileno (FILE *stream);
stream
Return File descriptor | -1 error
Using a temporal file
#include <stdio.h>
char *tmpnam ( char *s);
char *tempnam (const char *dir, const char *pfx);
-> 중복 되지 않도록 임시파일명 생성 (파일명만 생성, 파일은 직접 열어야 함)
#include <stdio.h>
FILE *tmpfile();
-> 임시 파일 포인터 생성 (파일명을 알 피요 없이, w+모드로 열린 파일 생성)