파일 지정자가 터미널을 사용하는지 검사한다.
#include <unistd.h> int isatty(int desc);
파일 지정자desc가 터미널에 연결되어 있는지 확인한다.
터미널에 연결되어 있을경우 1을 그렇지 않을 경우 0을 반환한다.
#include <sys/stat.h> #include <fcntl.h> #include <sys/types.h> int main() { int fd; // 표준입력은 터미널에 연결되어 있으므로 1을 출력한다. printf("%d\n", isatty(0)); // 파일은 터미널에 연결되어 있지 않으므로 0을 출력한다. fd = open("test100", O_RDWR); printf("%d\n", isatty(fd)); close(fd); fd = open("/dev/ttyS0", O_RDONLY); if (fd < -1) { printf("open error\n"); exit(0); } printf("%d\n", isatty(fd)); close(fd); exit(0); }
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
1장. isatty(3)
파일 지정자가 터미널을 사용하는지 검사한다.
1.1절. 사용법
1.2절. 설명
파일 지정자desc가 터미널에 연결되어 있는지 확인한다.
1.3절. 반환값
터미널에 연결되어 있을경우 1을 그렇지 않을 경우 0을 반환한다.
1.4절. 예제
Recent Posts
Archive Posts
Tags