fileno() — Determine File Handle

Format

#include <stdio.h>
int fileno(FILE *stream);

Language Level: XPG4

Threadsafe: Yes.

Integrated File System Interface: This function is not available when SYSIFCOPT(*NOIFSIO) is specified on the compilation command.

Description

The fileno() function determines the file handle that is currently associated with stream.

Return Value

If the environment variable QIBM_USE_DESCRIPTOR_STDIO is set to Yes, the fileno()function returns 0 for stdin, 1 for stdout, and 2 for stderr.

With QIBM_USE_DESCRIPTOR_STDIO set to No, the ILE C session files stdin, stdout, and stderr do not have a file descriptor associated with them. The fileno() function will return a value of -1 in this case.

The value of errno can be set to EBADF.

Example that uses fileno()

This example determines the file handle of the stderr data stream.

/* Compile with SYSIFCOPT(*IFSIO)         */
 #include <stdio.h>
 
 int main (void)
   {
   FILE *fp;
   int result;
 
   fp = fopen ("stderr","w");
 
   result = fileno(fp);
   printf("The file handle associated with stderr is %d.\n", result);
   return 0;
 
   /*****************************************************************
    * The output should be:
    *
    * The file handle associated with stderr is -1.
    ****************************************************************/
  }

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]