

fileno()                  STDIO Function                 fileno()




Get file descriptor

#include <stdio.h>
iinntt ffiilleennoo(_f_p) FFIILLEE *_f_p;

fileno  returns  the file  descriptor  associated  with the  file
stream fp.   The file descriptor is the  integer returned by open
or creat.  It is used by  routines such as fopen to create a FFIILLEE
stream.

***** Example *****

This example reads a file descriptor and prints it on the screen.


#include <stdio.h>



main(argc,argv)
int argc; char *argv[];
{
        FILE *fp;
        int fd;



        if (argc !=2) {
                printf("Usage: fd_from_fp filename\n");
                exit(0);
        }



        if ((fp = fopen(argv[1], "r")) == NULL) {
                printf("Cannot open input file\n");
                exit(0);
        }



        fd = fileno(fp);
        printf("The file descriptor for %s is %d\n",
                argv[1], fd);
}


***** See Also *****

FILE, file descriptor, STDIO






COHERENT Lexicon                                           Page 1


