#include <lcio.h> int fileno(FILE *f);Here is the synopsis for the POSIX implementation
#include <stdio.h> int fileno(FILE *f);
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 OpenEdition 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 OpenEdition file,
or is not one of stdin
, stdout
, or
stderr
, it fails and returns a - 1.
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
OpenEdition returns a - 1, except for stdin
, stdout
,
or stderr
, for which fileno
returns 0, 1, or 2 respectively.
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 filen", 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; }
fdopen
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.