Chapter Contents |
Previous |
Next |
fileno |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <lcio.h> int fileno(FILE *f);
Here is the synopsis for the POSIX implementation
#include <stdio.h> int fileno(FILE *f);
DESCRIPTION |
fileno
returns the file number of the stream associated with the
FILE
object addressed by
f
. If
fileno
is called for a file open to an HFS file,
it returns the USS file descriptor for the file. If
fileno
is called for a socket, it returns the simulated file-descriptor
number for the socket. If
fileno
is called
for a file that is not an USS file, it fails and returns a -1.
RETURN VALUE |
fileno
returns an integer file number. If
f
is
0 or is not associated with an open stream, the value returned by
fileno
is unpredictable.
fileno
of a stream that is not USS returns a -1.
EXAMPLE |
This example illustrates truncating an
HFS file accessed by standard I/O.
fileno
obtains the file number, and then
ftruncate
is called to truncate the file.
fflush
is called before truncation to ensure that any buffered data are flushed:
/* This example must be compiled with the posix option. */ #include <stdio.h> #include <sys/types.h> #include <unistd.h> int stdtrunc(FILE *f, long pos) { int fd; int rc; /* Get POSIX file descriptor. */ fd = fileno(f); if (fd == -1) { fputs("Cannot truncate non-HFS file\n", stderr); return -1; } rc = fflush(f); if (rc != 0) { perror("fflush error"); return -1; } /* Truncate file to requested position. */ rc = ftruncate(fd, pos); if (rc == -1) perror("ftruncate error"); return rc; }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.