๐strdup
โ๏ธ ํจ์ ํ๋กํ ํ์
char *strdup(const char *s1);
โ๏ธ ํจ์์ ์ญํ : s1์ ๋ณต์ฌํ ๋ฉ๋ชจ๋ฆฌ์ ํ ๋น ํ ๊ทธ ๋ฉ๋ชจ๋ฆฌ์ ๋ณต์ฌ
โ๏ธํจ์ ๋ฐํ๊ฐ
โ๏ธ ์ฑ๊ณต์, ํ ๋น๋ ๋ฉ๋ชจ๋ฆฌ์ ํฌ์ธํฐ
โ๏ธ ์คํจ์, NULL
โ๏ธ man page์ ๋์จ ์ค๋ช !
๐ 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 may subsequently be used as an argument to the function free(3).
If insufficient memory is available, NULL is returned and errno is set to ENOMEM.
โฟํด์ : strudup() ํจ์๋ string s1์ ๋ณต์ฌํ ์ถฉ๋ถํ ๋ฉ๋ชจ๋ฆฌ๋ฅผ ํ ๋นํ๊ณ , ๋ณต์ฌํ๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ ํฌ์ธํฐ๋ฅผ ๋ฐํํ๋ค. ๊ทธ ํฌ์ธํฐ๋ ์๋ง ๊ทธ ํ free()ํจ์์ argument๋ก ์ฐ์ผ ๊ฒ์ด๋ค. ๋ง์ฝ ์ถฉ๋ถํ ๋ฉ๋ชจ๋ฆฌ๊ฐ ์ฌ์ฉ ๊ฐ๋ฅํ์ง ์๋ค๋ฉด, NULL์ด ๋ฐํ๋๊ณ errno๊ฐ ENOMEM์ ์ค์ ๋๋ค.
'๐ฐ42์์ธ > libft' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[42์์ธ] libft ์ ๋ฆฌ : ft_strlen, ft_strlcpy, ft_strlcat ๊ตฌํ (0) | 2022.02.07 |
---|---|
[42์์ธ] libft ์ ๋ฆฌ : ft_toupper, ft_tolower ๊ตฌํ (0) | 2022.01.14 |
[42์์ธ] libft ์ ๋ฆฌ : ft_isalpha, ft_isdigit, ft_isalnum, ft_isascii, ft_isprint ๊ตฌํ (0) | 2022.01.13 |
[42์์ธ] libft ์ ๋ฆฌ: calloc (0) | 2022.01.04 |
[42์์ธ] libft ์ ๋ฆฌ : strnstr (0) | 2022.01.04 |