목차
파일처리론
제목 : C 언어 파일 관련 함수 조사 정리
1. 고수준, 저수준 I/O Function의 종류와 특징 비교
1)고수준 I/O Function
2) 저수준 I/O Function
1. 고수준
제목 : C 언어 파일 관련 함수 조사 정리
1. 고수준, 저수준 I/O Function의 종류와 특징 비교
1)고수준 I/O Function
2) 저수준 I/O Function
1. 고수준
본문내용
안함
_O_SHORT_LIVED파일 추가_O_CREAT와 함께 사용되며 임시파일을 만든다.
_O_TEMPORARY파일 추가_O_CREAT와 함께 사용되며 파일을 닫을때 삭제한다.
_O_EXCL파일 추가_O_CREAT와 함께 사용되며 파일이 이미 존재할 경우 에러를 발생시킨다.
_O_RANDOM최적화캐시를 임의 접근 방식으로 최적화한다.
_O_SEQUENTIAL최적화캐시를 순차 접근 방식으로 최적화 한다.
_O_TRUNC기타파일을 열면서 크기를 0으로 만든다.
...(int permission)
허가모드를 정함. 연산모드가 O_CREAT인 경우에만 서술 가능하다.
S_IWRITE : 쓰기 허가
S_IREAD : 읽기 허가
S_IREAD | S_IWRITE : 읽고 쓰기 허가
- 리턴 값 : 파일의 핸들값이 int형으로 리턴되고 실패하면 1이 리턴된다.
- example
/* _opne */
#include
#include
#include
int main(void)
{
int handle;
handle = _open("abc.txt", O_CREAT);
if(handle == -1)
perror(“error detected”);
printf("핸들값 : %d\n", handle);
if(_close(handle) == -1)
{
printf("정상 종료 실패\n");
return 0;
}
printf("정상종료 \n");
return 0;
}
int _close(int fd)
- 기능 : 파일을 닫는다.
- 인자 : int fd
핸들값
- 리턴 값 : 파일닫기가 성공하면 0, 실패하면 1이 리턴된다.
- example
/* _close */
(*open과 동일*)
int _read(int handle, char *buffer, unsigned int count)
- 기능 : handle에 관계되는 파일로부터 count에 해당하는 바이트만킁 읽어서 buffer에 기억시키는 함수
- 인자 : int handle, char *buffer, unsigned int count
int handle
파일의 핸들값
char *buffer
handle의 내용으로부터 읽어와 저장할 공간
unsigned int count
입력받을 크기. 바이트
- 리턴 값 : 정상적으로 읽으면 읽은 문자 수, 파일 끝에 이르면 0, 오류가 발생할 경우는 1을 리턴한다.
- example
#include
#include
#include
int main(void){
int handle;
char c[81] = "hello";
handle = _open("abc.txt", O_RDWR | O_CREAT);
if(handle == -1)
perror(“error detected”);
printf("핸들값 : %d\n", handle);
_write(handle, "hello", 6);
_read(handle, c, 6);
printf("%s\n", c);
if(_close(handle) == -1){
printf("정상 종료 실패\n");
return 0;
}
printf("정상종료 \n");
return 0;
}
int _write(int handle, char *buffer, unsigned int count)
- 기능 : buffer로부터 handle에 관계된 파일에 count에 해당하는 바이트만큼 쓰는 함수
- 인자 : int handle, char *buffer, unsigned int count
int handle
파일의 핸들값
char *buffer
파일에 입력할 내용
unsigned int count
입력할 크기. 바이트
- 리턴 값 : 정상적으로 기록하면 기록한 문자 수, 오류가 발생하면 1을 리턴한다.
- example
/* writh */
( read와 동일 )
long _lseek(int handle, long offset, int pos)
- 기능 : handle에 관계되는 파일의 파일포인터를 pos 위치로부터 offset 바이트만큼 새로운 위치로 옮기는 함수이다.
- 인자 : int handle, long offset, int pos
int pos
파일포인터의 시작 위치를 정해준다.
0 또는 SEEK_SET : 파일의 시작
1 또는 SEEK_CUR : 파일 포인터의 현재 위치
2 또는 SEEK_END : 파일의 끝
- 리턴 값 : 정상적으로 파일포인터가 정해지면 offset을 반환하고, 실패하면 1L을 리턴한다.
- example
#include
#include
#include
int main(void)
{
long pos;
int handle;
handle = _open("abc.txt", O_RDWR | O_CREAT);
_write(handle, "hello", 6);
pos = _lseek(handle, 0L, SEEK_END);
printf("%d\n", (int)pos);
return 0;
}
int _eof(int handle)
- 기능 : 파일을 읽을 때 파일의 끝에 도달했는지를 결정하는 함수
- 인자 : int handle
- 리턴 값 : 파일의 끝일 때 1, 정상적인 상태일 때 0, 오류시에는 1을 리턴한다.
- example
/* _eof */
#include
#include
#include
#include
int main(void)
{
int fh, count, total = 0;
char buf[10];
if( (fh = _open( "abc.txt", _O_RDONLY )) == - 1 )
{
perror("열기 실패");
exit( 1 );
}
while( !_eof( fh ) )
{
if( (count = _read( fh, buf, 10 )) == -1 )
{
perror( "읽기 실패" );
break;
}
total += count;
}
printf( "읽은 크기 = %d\n", total );
_close( fh );
return 0;
}
_O_SHORT_LIVED파일 추가_O_CREAT와 함께 사용되며 임시파일을 만든다.
_O_TEMPORARY파일 추가_O_CREAT와 함께 사용되며 파일을 닫을때 삭제한다.
_O_EXCL파일 추가_O_CREAT와 함께 사용되며 파일이 이미 존재할 경우 에러를 발생시킨다.
_O_RANDOM최적화캐시를 임의 접근 방식으로 최적화한다.
_O_SEQUENTIAL최적화캐시를 순차 접근 방식으로 최적화 한다.
_O_TRUNC기타파일을 열면서 크기를 0으로 만든다.
...(int permission)
허가모드를 정함. 연산모드가 O_CREAT인 경우에만 서술 가능하다.
S_IWRITE : 쓰기 허가
S_IREAD : 읽기 허가
S_IREAD | S_IWRITE : 읽고 쓰기 허가
- 리턴 값 : 파일의 핸들값이 int형으로 리턴되고 실패하면 1이 리턴된다.
- example
/* _opne */
#include
#include
#include
int main(void)
{
int handle;
handle = _open("abc.txt", O_CREAT);
if(handle == -1)
perror(“error detected”);
printf("핸들값 : %d\n", handle);
if(_close(handle) == -1)
{
printf("정상 종료 실패\n");
return 0;
}
printf("정상종료 \n");
return 0;
}
int _close(int fd)
- 기능 : 파일을 닫는다.
- 인자 : int fd
핸들값
- 리턴 값 : 파일닫기가 성공하면 0, 실패하면 1이 리턴된다.
- example
/* _close */
(*open과 동일*)
int _read(int handle, char *buffer, unsigned int count)
- 기능 : handle에 관계되는 파일로부터 count에 해당하는 바이트만킁 읽어서 buffer에 기억시키는 함수
- 인자 : int handle, char *buffer, unsigned int count
int handle
파일의 핸들값
char *buffer
handle의 내용으로부터 읽어와 저장할 공간
unsigned int count
입력받을 크기. 바이트
- 리턴 값 : 정상적으로 읽으면 읽은 문자 수, 파일 끝에 이르면 0, 오류가 발생할 경우는 1을 리턴한다.
- example
#include
#include
#include
int main(void){
int handle;
char c[81] = "hello";
handle = _open("abc.txt", O_RDWR | O_CREAT);
if(handle == -1)
perror(“error detected”);
printf("핸들값 : %d\n", handle);
_write(handle, "hello", 6);
_read(handle, c, 6);
printf("%s\n", c);
if(_close(handle) == -1){
printf("정상 종료 실패\n");
return 0;
}
printf("정상종료 \n");
return 0;
}
int _write(int handle, char *buffer, unsigned int count)
- 기능 : buffer로부터 handle에 관계된 파일에 count에 해당하는 바이트만큼 쓰는 함수
- 인자 : int handle, char *buffer, unsigned int count
int handle
파일의 핸들값
char *buffer
파일에 입력할 내용
unsigned int count
입력할 크기. 바이트
- 리턴 값 : 정상적으로 기록하면 기록한 문자 수, 오류가 발생하면 1을 리턴한다.
- example
/* writh */
( read와 동일 )
long _lseek(int handle, long offset, int pos)
- 기능 : handle에 관계되는 파일의 파일포인터를 pos 위치로부터 offset 바이트만큼 새로운 위치로 옮기는 함수이다.
- 인자 : int handle, long offset, int pos
int pos
파일포인터의 시작 위치를 정해준다.
0 또는 SEEK_SET : 파일의 시작
1 또는 SEEK_CUR : 파일 포인터의 현재 위치
2 또는 SEEK_END : 파일의 끝
- 리턴 값 : 정상적으로 파일포인터가 정해지면 offset을 반환하고, 실패하면 1L을 리턴한다.
- example
#include
#include
#include
int main(void)
{
long pos;
int handle;
handle = _open("abc.txt", O_RDWR | O_CREAT);
_write(handle, "hello", 6);
pos = _lseek(handle, 0L, SEEK_END);
printf("%d\n", (int)pos);
return 0;
}
int _eof(int handle)
- 기능 : 파일을 읽을 때 파일의 끝에 도달했는지를 결정하는 함수
- 인자 : int handle
- 리턴 값 : 파일의 끝일 때 1, 정상적인 상태일 때 0, 오류시에는 1을 리턴한다.
- example
/* _eof */
#include
#include
#include
#include
int main(void)
{
int fh, count, total = 0;
char buf[10];
if( (fh = _open( "abc.txt", _O_RDONLY )) == - 1 )
{
perror("열기 실패");
exit( 1 );
}
while( !_eof( fh ) )
{
if( (count = _read( fh, buf, 10 )) == -1 )
{
perror( "읽기 실패" );
break;
}
total += count;
}
printf( "읽은 크기 = %d\n", total );
_close( fh );
return 0;
}
추천자료
컴퓨터 구조의 전반적인 이해 - 100장에 걸친 요약 리포트
빌게이츠의기업론
[컴퓨터운영체제][컴퓨터운영체계][OS]컴퓨터운영체제(OS), DOS(도스), 윈도우즈, 윈도우즈 3...
컴퓨터운영체제(OS)의 개념과 종류, 컴퓨터운영체제(OS)의 구성과 기능, 컴퓨터운영체제(OS)...
[소프트웨어] Labview(랩뷰)의 소개, 특징, 구조 및 응용분야, 사용분야에 대하여
[IT와경영정보시스템]하드웨어 분류 방식 중 직렬처리 방식에 비해 병렬처리 방식의 특징을 ...
3D 컴퓨터그래픽의 정의, 3D 게임의 기획 의도와 3D 게임의 국내, 국외 연구 동향, 3D 게임의...
클러스터 시스템에서의 자원 관리 프로그래밍 모델
컴퓨터보조학습(CAI, 컴퓨터보조수업)의 기원, 컴퓨터보조학습(CAI, 컴퓨터보조수업)의 현황...
CAI(컴퓨터보조수업, 컴퓨터보조학습)의 유형, CAI(컴퓨터보조수업, 컴퓨터보조학습)의 개발...
전자상거래 시스템 구성(전자상거래 하드웨어시스템, 인터넷 프로그래밍, 운영환경)
[컴퓨터바이러스]컴퓨터바이러스의 개념, 종류, 컴퓨터바이러스의 약력, 증상, 컴퓨터바이러...
나의 존경하는사람에 대하여
[방송통신대과제물]인간과과학-인공지능의 발달이 인류사회를 어떻게 변화시킬 수 있을지 생...