#include <unistd.h>
|
int
isatty (int fd); |
The isatty function determines if the file descriptor fd refers to a valid terminal type device.
#include<unistd.h> #include<stdio.h> #include<fcntl.h> //O_APPEND int main() { int x = isatty(0); //stdin (fd = 0) int y = isatty(1); //stdout (fd = 1) int z = isatty(2); //stderr (fd = 2) printf("{Expected: 1 1 1} %d %d %d\n", x, y, z); int i = isatty(5); //some invalid fd int fd_file = open("c:\ome.txt", O_APPEND); int j = isatty(fd_file); //valid fd of a text file int fd_pipe[3]; int p = pipe(fd_pipe); int k = isatty(fd_pipe[1]); //valid fd of a pipe close(fd_file); close(fd_pipe[0]); close(fd_pipe[1]); printf("{Expected: 0 0 0} %d %d %d\n", i, j, k); unlink("c:\ome.txt"); return 0; }
Output
{Expected: 1 1 1} 1 1 1 {Expected: 0 0 0} 0 0 0
© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user. |