File I/O2 [CS] File, File descriptor #4 이 포스팅은 한국기술교육대학교 김덕수 교수님의 시스템 프로그래밍 (CSE 232)를 참고하여 작성되었습니다. #1 Duplication FD - dup(2) / dup2(2) #include int dup(int oldfd); int dup2(int oldfd, int newfd); oldfd (old file descriptor) : 복사하려는 file descriptor newfd (old file descriptor) : 새로운 fd 지정, dup()의 경우 할당 가능한 fd 중 가장 작은 값 할당 Return : oldfd를 복사한 새로운 fd , -1 = error IO redirection #include #include #include #include int main(void) { int f.. 2022. 12. 13. [CS] File, 파일 읽기/쓰기 #3 이 포스팅은 한국기술교육대학교 김덕수 교수님의 시스템 프로그래밍 (CSE 232)를 참고하여 작성되었습니다. #1 Reading a file - read(2) #include ssize_t read(int fd, void *buf, size_t count); fd (file descriptor) : 읽으려는 파일의 file descriptor buf (buffer) : 읽은 내용을 저장할 buffer의 시작 주소 주의사항 : byte 단위를 읽는 것이기 때문에 void 포인터 형태로 넣어야 한다. count : 읽을 byte의 수 Return : 실제로 읽은 byte의 수 0 = 파일의 끝(EOF)에 도달, -1 = 에러 #2 Writing to a file - write(2) #include ssize.. 2022. 12. 13. 이전 1 다음