C,C++ & Linux
-
C/C++ lseek 함수 - 파일 커서(seek pointer) 조정C,C++ & Linux 2020. 4. 22. 00:23
lseek 기능 함수의 seek pointer (커서) 를 조정하는 함수입니다. 조정된 seek pointer 는 파일의 read/write 시 사용됩니다. 특정 위치부터 읽거나 쓰고싶을때 유용합니다. 파일을 처음 열면 최초의 seek position 은 0입니다. O_APPEND 플래그를 주어 열게되면 최초의 seek position 은 파일의 끝에 있습니다. 함수 원형 #include #include off_t lseek(int fd, off_t offset, int whence); 매개변수 int fd 조정할 파일의 파일 디스크립터 off_t offset 기준점으로부터 이동할 거리(offset) int whence 기준점 SEEK_SET(0) : 파일의 맨 앞 SEEK_CUR(1) : 현재 Seek..
-
C/C++ creat 함수 - 파일 생성C,C++ & Linux 2020. 4. 21. 23:41
crea 함수 기능 파일을 만들어주는 함수 (create 가 아님에 주의하자) 함수 원형 #include #include #include int creat(const char *filepath, mode_t mode); 매개변수 const char *filepath 생성할 파일의 경로 mode_t mode 생성할 파일의 접근 권한을 명시 기본 값 파일 : 0666 디렉토리 : 0777 아래 옵션들은 bitwise 연산으로 여러개를 동시에 사용가능함 S_IRWXU : 유저 읽기, 쓰기, 실행 권한 (Read, Write, Execute User) S_IRUSR : 유저 읽기 권한 (Read User) S_IWUSR : 유저 쓰기 권한 (Write User) S_IXUSR : 유저 실행 권한 (Execute..
-
C/C++ open 함수 - 파일 생성 / 읽기 / 쓰기C,C++ & Linux 2020. 4. 21. 23:22
Open 함수 기능 파일을 열거나 생성 후 열어주는 함수 함수원형 #include #include #include int open(const char *filepath, int flag); int open(const char *filepath, int flag, mode_t mode); 매개변수 const char *filepath 열고자 하는 파일의 경로 int flag 파일 열 때 사용할 옵션 O_RDONLY : 읽기 모드 (Read Only) O_WRONLY : 쓰기 모드 (Write Only) - 읽지 않고 쓰기만 하는 경우는 크게 많지 않음 O_RDWR : 읽기/쓰기 모드 O_CREAT : 파일 생성 O_APPEND : 파일을 쓰되 기존 파일의 맨 끝부터 이어 쓰는 기능 O_TRUNC : 파일을..
-
string.h 함수 모음C,C++ & Linux 2020. 4. 6. 23:23
void* memchr(const void* str, int c, size_t n); str 에서부터 n바이트 내에 있는 최초의 문자 c를 찾아주는 함수 리턴 값 : 최초의 문자 c가 존재한다면 c가 최초로 등장하는 곳, 없다면 NULL int memcmp(const void* str1, const void* str2, size_t n); str1, str2 의 n바이트가 일치하는지 비교해주는 함수 리턴값 0 이면 str2가 str1 보다 작음 리턴값 == 0 이면 str1과 str2 가 같음 void* memcpy(void* dest, const void* src, size_t n); src의 데이터 n바이트를 dest로 복사해주는 함수 리턴 값 :..
-
리눅스 시스템 프로그래밍 기본 명령어 모음C,C++ & Linux 2020. 4. 6. 20:52
파일 입출력 open #include #include #include int open(const char* pathname, int oflag); int open(const char* pathname, int oflag, mode_t mode); // 리턴값 : 성공 시 파일 디스크립터, 에러 시 -1 (errno 설정) close #include int close(int fd); // 리턴 값 : 성공 시 0, 에러 시 -1 (errno 설정) creat #include #include #include int creat(const char* pathname, mode_t mode); // 리턴 값 : 성공 시 0, 에러 시 -1 (errno 설정) lseek #include #include off_t ..