본문 바로가기

C언어7

파일 디스크립터(File Descriptor)란? 파일 디스크립터 (FD, File Descriptor)란, Unix OS에서 네트워크 소켓과 같은 파일이나 기타 입력/출력 리소스에 액세스하는 데 사용되는 추상표현이다. 즉, 시스템으로 부터 할당받은 파일이나 소켓을 대표하는 정수다. 파일 디스크립터는 음이 아닌 정수(Non-negative Integer)로, 일반적으로 형식 int로 C 프로그래밍 언어로 표현된다(음수 값은 "무값" 또는 오류 조건을 나타내기 위해 예약된다). (Window에서는 file handle이라고 부르고 값은 랜덤하게 할당된다.) FD의 0번에서 2번까지는 고정되어 있다. (unistd.h 헤더파일에 명시) 각 Unix 프로세스는 세 가지 standard streams에 해당하는 고정된 standard POSIX file des.. 2020. 10. 13.
[C언어] 내장함수 비교 - memcpy, memccpy / memmove / memchr / memcmp #include 에 있는 메모리 관련 함수를 정리한다. 레퍼런스는 man 가이드다. memcpy와 memccpy 비교 메모리 영역을 복사하는 함수다. PROTOTYPE #include void *memcpy (void *restrict dst, const void *restrict src, size_t n); #include void *memccpy (void *restrict dst, const void *restrict src, int c, size_t n); NAME copy memory area copy string until character found DESCRIPTION The memcpy() function copies n bytes from memory area src to memory .. 2020. 10. 8.
[C언어] 내장함수 비교 - strchr, strrchr / strstr, strnstr / strcmp, strncmp 에 있는 문자열 관련 함수를 정리한다. 레퍼런스는 man 가이드다. strchr와 strrchr 비교 RETURN 항목에서 말하는 'character'는 byte를 의미한다. PROTOTYPE #include char *strchr(const char *s, int c); #include char *strrchr(const char *s, int c); NAME locate character in string DESCRIPTION - The strchr() function locates the first occurrence of c (converted to a char) in the string pointed to by s. - The terminating null character is consider.. 2020. 10. 8.
[C언어] 내장함수 비교 - strdup, malloc, calloc, free 에 정의된 strdup 함수와, 에 정의되어 있는 동적 메모리(dynamic memory) 할당 및 해제 함수 몇 가지를 정리한다. 리퍼런스는 man 가이드다. strdup strdup 함수는 동적 메모리를 할당하여 문자열을 복사하므로 malloc 함수를 사용한다. PROTOTYPE #include void *strdup(const char *s1); NAME duplicate a string (save a copy of a string) DESCRIPTION - The strdup() function allocates sufficient memory for a copy of the string s1, does the copy, and returns a pointer to it. - The pointer.. 2020. 10. 7.
[C언어] NULL, 0, NUL, '\0', undefined의 차이 malloc(), bzero() 등의 C언어 내장함수를 공부하면서 NULL, 0, NUL, '\0'을 접하게 된다. 공통점과 차이점을 정확하게 정리하고자 한다. 우선 NULL과 NUL은 구분되며, 비교항목을 NULL, 0 과 NUL, '\0' 과 undefined 로 나눌 수 있다. NULL, 0 비교 NULL은 널 포인터로서, (void *)0을 가리킨다. NULL 매크로는 , 등 여러 헤더파일에서 이미 정의돼있다. C언어에서 pointer와 정수는 서로 형 변환될 수 있는데, 두 데이터 타입 모두 4byte다. Null pointer는 정수 0으로 변환될 수 있고, 정수 0은 Null pointer로 변환될 수 있다. 즉, Null pointer는 메모리 주소 0을 가르키는 pointer라는 뜻이다... 2020. 10. 6.