Name

isatty - determines if the file descriptor refers to a valid terminal type device.

Library

libc.lib

Synopsis

  #include <unistd.h>
  int isatty (int fd);

Return values

The isatty returns 1 if fd is an open descriptor connected to a terminal; returns 0 otherwise.

Detailed description

This function operate on the system file descriptors for character special devices.

The isatty function determines if the file descriptor fd refers to a valid terminal type device.


Examples

#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:\\some.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:\\some.txt");
 
 return 0;
}


Output

{Expected: 1 1 1} 1 1 1
{Expected: 0 0 0} 0 0 0


See also

ioctl

Feedback

For additional information or queries on this page send feedback

© 2008 Nokia Corporation. All rights reserved. This documentation can be used in the connection with this Product to help and support the user.

Top