๐ libft
@42seoul : (2020.04.15 ~ 2020.05.01)
๐ About
- ์ผ๋ฐ์ ์ผ๋ก C์ธ์์ ์์ฃผ ์ฌ์ฉํ๋ ํจ์๋ค์ ์ง์ ๊ตฌํํฉ๋๋ค. (The aim of this project is to code a C library regrouping usual functions that you’ll be allowed to use in all your other projects.)
- ๊ตฌํ ๋ชฉ๋ก
- Libc Functions :
<ctype.h>
,<string.h>
<stdlib.h>
- Non- Libc Functions
- Linked-list Functions
- Libc Functions :
๐ Review
- C์์ includeํ์ฌ ์ฌ์ฉํ๋
<ctype.h>
,<string.h>
<stdlib.h>
์ ํจ์ ๋ฟ๋ง ์๋๋ผ ์์ฃผ ์ฌ์ฉ๋๋ split, join ํจ์ ๋ฑ ์ง์ ๊ตฌํํ๋ฉด์ C์ ๊ธฐ๋ณธ ๋ฌธ๋ฒ๊ณผ ํฌ์ธํฐ ์ฐ์ฐ, ๋ฉ๋ชจ๋ฆฌ ๊ด๋ฆฌ(Heap), Makefile ๋ฑ ๋ฐฐ์ธ ์ ์์๋ค. - Libc์ ์ด๋ฏธ ๊ตฌํ๋์ด ์๋ ํจ์๋ค์ ๊ฐ์ ธ๋ค ์ฐ๋ฉด ๋๋๋ฐ ๊ณผ์ ํ๋ฉด์ ์ ๋ด๊ฐ ๊ตฌํํด์ผํ ๊น ๊ณ ๋ฏผ๋ ๋ง์ด ํ์ง๋ง ์ง์ ๋ฐ๋จ์์ ํจ์๊ฐ ์ด๋ ๊ฒ ๋์ํ๋๊ตฌ๋ ์๊ฐํ ์ ์์ด์ ๋ฌด์ฒ ์ ์ตํ๋ค. GNU์ Libc์ ๋ด๊ฐ ์ง ์ฝ๋ ๋ฒค์น๋งํน ํ๋๋ฐ ์ฒ์ฐธํ๊ฒ ๋ฌด๋์ก๋ค. Libc๋ ์ด์ ๋ธ๋ฆฌ๋ก ์๋ฒฝํ ์ต์ ํ ๋์ด์์ด ๋น์ฐํ ๊ฒฐ๊ณผ์์ง๋ง ๋์ผ๋ก ๋ณด๋ ๋น์ฐธํ๋ฉด์ ์ฝ๊ฐ ์์ฌ์ด ์๊ฒผ๋ค. ํ์ง๋ง ์์ฌ๋ง ๊ฐ๊ณ ๋ค๋ฅธ ํ๋ก์ ํธ๋ฅผ ํ์.
๐ Run
Unit Test : All Success
alelievr
๋์ด ๋ง๋ ์ฝ๋๋ก ์ ์ฒด์ ์ธ ์ ๋ํ ์คํธ๋ฅผ ํ์ธํ์๋ค. ๋ชจ๋ ์ฝ๋ ์ด์ ์์ด libc์ ๋์ผํ๊ฒ ๋์ํ๋ค.

Benchmark (My functions vs Libc)
- ์ฑ๋ฅ์ฐจ์ด : ๋ง๊ฒ๋ 50๋ฐฐ, ์ ๊ฒ๋ 1.2๋ฐฐ ์ ๋ Libc ํจ์๋ค์ด ๋ ๋น ๋ฅด๊ฒ ๋์๋ค.
- atoi ํจ์๋ ๊ฑฐ์ ๋์ผํ๊ฒ ๋์จ๋ค.
- ์ํจ

๐ Function List
๐ Libc functions (Standard C Library)
<ctype.h>
,<string.h>
<stdlib.h>
์ ๋ช ๊ฐ์ง ํจ์๋ฅผ ๊ตฌํํฉ๋๋ค.
Description : man [function]
Type | Function |
---|---|
<string.h> : memory |
memset , memcpy , memccpy ,memmove , memchr , memcmp |
<string.h> : string |
strlen , strlcpy , strlcat , strchr , strrchr , strnstr , strncmp , strdup |
<stdlib.h> |
calloc , atoi |
<ctype.h> |
isalpha , isdigit , isalnum , isascii , isprint , toupper , tolower |
๐ Additional functions
- libc์ ํฌํจ๋์ง ์์ง๋ง ์์ฃผ ์ฌ์ฉํ๋ ํจ์๋ฅผ ๊ตฌํํฉ๋๋ค.
- string : ๋ฌธ์์ด ์ฒ๋ฆฌ ํจ์
- put_fd : ๋ฌธ์์ด ์ถ๋ ฅ ํจ์
Type | Function | Description |
---|---|---|
string |
ft_substr | Allocates (with malloc(3)) and returns a substring from the string ’s’. The substring begins at index ’start’ and is of maximum size ’len’. |
string |
ft_strjoin | Allocates (with malloc(3)) and returns a new string, which is the result of the concatenation of ’s1’ and ’s2’. |
string |
ft_strtrim | Allocates (with malloc(3)) and returns a copy of ’s1’ with the characters specified in ’set’ removed from the beginning and the end of the string. |
string |
ft_split | Allocates (with malloc(3)) and returns an array of strings obtained by splitting ’s’ using the character ’c’ as a delimiter. The array must be ended by a NULL pointer. |
string |
ft_itoa | Allocates (with malloc(3)) and returns a string representing the integer received as an argument. Negative numbers must be handled. |
string |
ft_strmapi | Applies the function ’f’ to each character of the string ’s’ to create a new string (with malloc(3)) resulting from successive applications of ’f’. |
put_fd |
ft_putchar_fd | Outputs the character ’c’ to the given file descriptor. |
put_fd |
ft_putstr_fd | Outputs the string ’s’ to the given file descriptor. |
put_fd |
ft_putendl_fd | Outputs the string ’s’ to the given file descriptor, followed by a newline. |
put_fd |
ft_putnbr_fd | Outputs the integer ’n’ to the given file descriptor. |
๐ Linked list
- ๋งํฌ๋ ๋ฆฌ์คํธ๋ฅผ ๊ตฌํํฉ๋๋ค.
Type | Function | Description |
---|---|---|
linked-list |
ft_lstnew | Allocates (with malloc(3)) and returns a new element. The variable ’content’ is initialized with the value of the parameter ’content’. The variable ’next’ is initialized to NULL. |
linked-list |
ft_lstadd_front | Adds the element ’new’ at the beginning of the list. |
linked-list |
ft_lstsize | Counts the number of elements in a list. |
linked-list |
ft_lstlast | Returns the last element of the list. |
linked-list |
ft_lstadd_back | Adds the element ’new’ at the end of the list. |
linked-list |
ft_lstdelone | Takes as a parameter an element and frees the memory of the element’s content using the function ’del’ given as a parameter and free the element. The memory of ’next’ must not be freed. |
linked-list |
ft_lstclear | Deletes and frees the given element and every successor of that element, using the function ’del’ and free(3). Finally, the pointer to the list must be set to NULL. |
linked-list |
ft_lstiter | Iterates the list ’lst’ and applies the function ’f’ to the content of each element. |
linked-list |
ft_lstmap | Iterates the list ’lst’ and applies the function ’f’ to the content of each element. Creates a new list resulting of the successive applications of the function ’f’. The ’del’ function is used to delete the content of an element if needed. |
๐ Reference
- man <string.h>
- man <stdlib.h>
- man <ctype.h>
- Linft Unit Test : Benchmark code
- ๐ผ ์ ์ฒด 42seoul Project repo
๐ง๐ป๐ป Author
๋๊ธ0