Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

freopen, freopen64 - flush and reopen stream

&pagelevel(4)&pagelevel

Name

Syntax

freopen, freopen64

#include <stdio.h>

FILE *freopen(const char *filename, const char *mode, FILE *stream);
FILE *freopen64(const char *filename, const char *mode, FILE *stream); 

Description

stream. Failure to flush or close the file successfully is ignored. The error and end-of-file indicators for the stream are cleared.

freopen() then opens the file whose pathname is the string pointed to by filename and associates the stream pointed to by stream with it. The mode argument is used just as in fopen() (see fopen()).

The original stream is closed regardless of whether the subsequent open succeeds.

For automatic conversion, the b for binary must not be specified in mode. Furthermore, the environment variable IO_CONVERSION must not be present or must have the value YES.

There is no difference in functionality between freopen and freopen64 except that freopen64 returns a pointer that can point past the 2GB limit freopen64() sets the O_LARGEFILE bit in the File status flag.

BS2000
See fopen(), fopen64(). (End)

Restriction
If stream references a BS2000 file and filename refers to a POSIX file, the POSIX file can be opened with freopen() only if stream refers to stdin, stdout or stderr. If this is not the case, only the BS2000 file is closed, and 0 is returned.

If stream references a POSIX file and filename refers to a BS2000 file, the BS2000 file can be opened with freopen() only if stream refers to stdin, stdout or stderr. If this is not the case, only the POSIX file is closed, and 0 is returned. This applies regardless of the current assignments for the standard streams. (End)

Return val.

Value of stream

 



if successful.

 

Null pointer

if an error occurs; errno is set to indicate the error.

Errors

freopen() will fail if:

 

 

EACCES

Search permission is denied on a component of the path,
or the file exists and the permissions specified by mode are denied,
or the file does not exist and write permission is denied for the parent directory of the file to be created.

 

EINTR

A signal was caught during the freopen() system call.

 

EISDIR

The named file is a directory and mode requires write access.

 

ELOOP

Too many symbolic links were found when resolving the path.

 

EMFILE

{OPEN_MAX} file descriptors are currently open in the calling process.

 

ENAMETOOLONG

 



The length of the path argument exceeds {PATH_MAX} or a component of the path is longer than {NAME_MAX}.

 

ENFILE

The maximum allowable number of files is currently open in the system.

 

ENOENT

The specified file does not exist or filename points to an empty string.

 

ENOSPC

The file does not exist, and the directory or file system in which a new file was to be created cannot be expanded.

 

ENOTDIR

A component of the pathname is not a directory.

 

ENXIO

The specified file is a character-oriented or block-oriented device file and the device assigned to this file does not exist.

 

EOVERFLOW

The specified file is a regular file, but its size cannot be represented correctly in an object of type off_t.

 

EROFS

The named file resides on a read-only file system and mode requires write access.

 

ETXTBSY

The file is a pure procedure file (shared text file) that is currently executing and write protection is required for mode.

Notes

freopen() is normally used to reassign the file pointers stdin, stdout and stderr to files other than the default files opened. stderr is not buffered by default, but can be buffered or line-buffered by using freopen().

The program environment determines whether freopen() is executed for a BS2000 or POSIX file.

BS2000
See fopen(). (End) 

See also

creat(), fclose(), fopen(), fdopen(), stdio.h.