Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 8

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 8

freopen(), freopen64()

Reopen a stream

Synopsis:

#include <stdio.h>

FILE* freopen( const char* filename,
               const char* mode,
               FILE* fp );

FILE* freopen64( const char* filename,
               const char* mode,
               FILE* fp );

Arguments:

filename
The name of the file to open.
mode
The mode to use when opening the file. For more information, see fopen().
fp
The stream to associate with the file.

Library:

libc

Use the -l c option to qcc to link against this library. This library is usually included automatically.

Description:

The freopen() and freopen64() functions close the open stream fp, open the file specified by filename, and associate its stream with fp.

The largest value that can be represented correctly in an object of type off_t shall be established as the offset maximum in the open file description.

Returns:

A pointer to the newly opened stream, or NULL if an error occurs (errno is set).

Errors:

EACCES
Search permission is denied on a component of the filename prefix, or the file exists and the permissions specified by mode are denied, or the file doesn't exist and write permission is denied for the parent directory of the file to be created.
EBADFSYS
While attempting to open the named file, either the file itself or a component of the filename prefix was found to be corrupted. A system failure — from which no automatic recovery is possible — occurred while the file was being written to, or while the directory was being updated. You'll need to invoke appropriate systems-administration procedures to correct this situation before proceeding.
EBUSY
File access was denied due to a conflicting open (see sopen()).
EINTR
The freopen() operation was interrupted by a signal.
EINVAL
The value of the mode argument is not valid.
EISDIR
The named file is a directory, and the mode argument specifies write-only or read/write access.
ELOOP
Too many levels of symbolic links or prefixes.
EMFILE
Too many file descriptors are currently in use by this process.
ENAMETOOLONG
The length of the filename string exceeds PATH_MAX, or a pathname component is longer than NAME_MAX.
ENFILE
Too many files are currently open in the system.
ENOENT
Either the named file or the filename prefix doesn't exist, or the filename argument points to an empty string.
ENOMEM
There is no memory for FILE structure.
ENOSPC
The directory or filesystem that would contain the new file can't be extended.
ENOSYS
The freopen() function isn't implemented for the filesystem specified in filename.
ENOTDIR
A component of the filename prefix isn't a directory.
ENXIO
The media associated with the file has been removed (e.g. CD, floppy).
EOVERFLOW
The named file is a regular file and the size of the file can't be represented correctly in an object of type off_t.
EROFS
The named file resides on a read-only filesystem.

Examples:

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
    FILE* fp;
    int c;

    /* Reopen the stdin stream so it's reading
     * from "file" instead of standard input.
     */
    fp = freopen( "file", "r", stdin );

    if( fp != NULL ) {
        /* Now we can read from "file" using the
         * stdin functions like fgetchar()...
         */
        while( ( c = fgetchar() ) != EOF ) {
            fputchar( c );
        }

        fclose( fp );
        
        return EXIT_SUCCESS;
    }
    
    return EXIT_FAILURE;
}

Classification:

freopen() is ANSI, POSIX 1003.1; freopen64() is Large-file support

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler No
Thread Yes

See also:

errno, fclose(), fcloseall(), fdopen(), fopen(), fopen64()


Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 283

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/f/freopen.html on line 283