ft_putchar_fd

one·2021년 1월 30일
0

✅ft_putchar_fd

  • Outputs the character ’c’ to the given file descriptor.
  • c를 파일 디스크립터로 출력

💾Prototype

void ft_putchar_fd(char c, int fd);

💻Parameters

  • c : The character to output.
  • fd : The file descriptor on which to write.

💻Return value

  • None

💾Code

#include "libft.h"

void	ft_putchar_fd(char c, int fd)
{
	if (fd < 0)
		return ;
	write(fd, &c, 1);
}

💡File Descripter (출처 : https://twofootdog.tistory.com/51)

  • 유닉스 시스템에서 프로세스가 파일을 다룰 때 파일 디스크립터(File Descriptor)라는 개념을 이용한다.
  • 파일 디스크립터는 0이 아닌 정수값(Non-negative Integer)을 갖는다.
  • 프로세스가 실행 중에 파일을 Open하면 커널은 해당 프로세스의 파일 디스크립터 숫자 중 사용하지 않는 가장 작은 값을 할당해준다. 그 다음 프로세스가 열려있는 파일에 시스템 콜을 이용해서 접근할 때, 파일 디스크립터(FD)값을 이용해서 파일을 지칭할 수 있다.
  • 기본적으로 할당되는 파일 디스크럽터
    - 0 : Standard input
    - 1 : Standard Output
    - 2 : Standard Error
profile
늘 호기심을 갖고, 새로운 것에 도전할 것.

0개의 댓글