임베디드/리눅스시스템프로그래밍(97)
-
저수준 파일 API-2
파일 열기, 닫기에 이어서 저수준 파일 디스크립터를 이용하여 text와 binary를 쓰는 방법 text 파일 쓰기 dprintf 파일 읽기 binary 파일 쓰기 write, pwrite 둘의 차이점은 (파일 시작 기준) offset 파라미터 유무 반환값과 count를 비교, 두 값이 차이가 나는 경우도 발생 파일 읽기 read, pread https://github.com/surinoel/lsp/blob/master/lsp10.c
2019.04.08 -
다양한 open flag
O_TRUNC : 파일의 크기를 0으로 초기화해서 실행, (truncate : 줄이다) O_APPEND: 덧붙여 쓰기 https://github.com/surinoel/lsp/blob/master/lsp09.c
2019.04.08 -
open API
1. !man 2 open 2. warning: implicit declaration of function ‘close’ [-Wimplicit-function-declaration] => #include 추가로 해결 가능 3. dprintf는 파일 디스크립터 기반의 쓰기 함수 https://github.com/surinoel/Linux-SP/blob/master/open.c
2019.04.08 -
저수준 파일 API
기존 파일 API였던 f-API와의 차이점은 f-API는 glibc로, Linux Kernel에서 제공하는 System call Open API로 짜여진 함수들이다. 사용자들이 사용하기 편하다는 장점이 있다. 반면, 저수준 파일 API인 open, close, lseek은 System call 자체라고 보면 된다. 좀 더 원론적인 API로 보다 넓은 환경에서 사용될 수 있다. (디바이스 파일, 특수 파일 등) * 현재 파일 오프셋을 출력하는 ftell에 대응하는 저수준 파일 API가 없다. 하지만 cur_offset = lseek(fd, 0, SEEK_CUR)로 대체할 수 있다.
2019.04.08 -
binary 파일 읽고 쓰기
data를 쓰고 읽는 API fwrite와 fread binary file을 읽고 싶을 때 hexdump 파일명 hexdump 파일명 -C (문자형태로) https://github.com/surinoel/Linux-SP/blob/master/fwrite.c
2019.04.07 -
text mode와 binary mode
1. text mode 문자를 저장할 때 사용되는 방식 "10"을 저장할 때 파일에는 "0x31, 0x30"이 저장된다 fputc/fputs/fprintf 그리고 fgetc/fgets/fscanf와 같은 API로 저장 가능 2. binary mode 데이터를 저장할 때 사용되는 방식 "10"을 저장할 때 파일에는 "0x0a"가 저장된다 fwrite/fread API를 사용하며, Linux hexdump로 읽을 수 있다
2019.04.07