fileno(3C)
_________________________________________________________________
fileno macro
Return the UNIX file number of the specified open file.
_________________________________________________________________
Calling Sequence
#include <stdio.h>
FILE *fp;
int no;
no = fileno(fp);
where no is the UNIX file number.
fp is a pointer to a stream.
Description
Use the fileno macro to find the UNIX file number of an open
file. The include file stdio.h defines this macro.
Returns
The fileno macro returns the UNIX file number of the open file
you specify. If the file is closed, it returns -1, which is not
a legal file number.
Related Functions
See also the channel function.
Example
/* Program test for the fileno() macro */
#include <stdio.h>
FILE *fopen(), *fp;
char c;
int i = 1, n;
main(argc, argv)
DG/UX 4.00 Page 1
Licensed material--property of copyright holder(s)
fileno(3C)
int argc;
char *argv[];
{
while (i < argc) {
fp = fopen(argv[i], "r");
printf("File %s is open on file number %d.\n",
argv[i], n = fileno(fp));
i++;
}
}
A call to the program test with the valid filenames a, b, c, d,
e, and f generates the output
File a is open on file 3.
File b is open on file 4.
File c is open on file 5.
File d is open on file 6.
File e is open on file 7.
File f is open on file 8.
DG/UX 4.00 Page 2
Licensed material--property of copyright holder(s)