- fd : 파일 디스크립터
- write, read, open 함수 등에 사용
- 여기서는 write 함수의 첫번째 인자를 조정하는 용도로 사용
ft_putchar_fd
c
#include "libft.h"
void ft_putchar_fd(char c, int fd)
{
write(fd, &c, 1);
}
ft_putendl_fd
c
#include "libft.h"
void ft_putendl_fd(char *s, int fd)
{
if (s)
{
ft_putstr_fd(s, fd);
write(fd, "\n", 1);
}
}
ft_putnbr_fd
c
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
char c;
if (n == -2147483648)
write(fd, "-2147483648", 11);
else if (n < 0)
{
write(fd, "-", 1);
ft_putnbr_fd(-n, fd);
}
else if (n < 10)
{
c = '0' + n;
write(fd, &c, 1);
return ;
}
else
{
ft_putnbr_fd(n / 10, fd);
ft_putnbr_fd(n % 10, fd);
}
}
ft_putstr_fd
c
#include "libft.h"
void ft_putstr_fd(char *s, int fd)
{
while (*s != '\0')
{
write(fd, s, 1);
s++;
}
}