freopen(), freopen64()

open a stream 

Function


SYNOPSIS

#include <stdio.h>

FILE *freopen(const char *filename, const char *type, FILE *stream);

FILE *freopen64(const char *filename, const char *type, FILE *stream);


DESCRIPTION

The freopen() function first attempts to flush the stream and close any file descriptor associated with stream. Failure to flush or close the file successfully is ignored. The error and end-of-file indicators for the stream are cleared.

The freopen() opens the file whose path name is the string pointed to by filename and associates the stream pointed to by stream with it. The type argument is used just as in fopen().

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

The freopen() function is typically used to attached the pre-opened streams associated with stdin, stdout, and stderr to other files.

When a stream is opened, it is fully buffered only if it does not refer to an interactive device.

The freopen64() function is identical to the freopen() function except that the underlying file descriptor is created with the O_LARGEFILE flag set. The freopen64() function is a part of the large file extensions.


PARAMETERS

filename 

Points to the name of the file.

type 

Indicates a character string that specifies the desired type of file access. The first character of this string must be one of r (open for reading), w (open for writing), or a (open for writing at the end of file —append).

After the first character, you several optional modifiers: b, open in binary mode; t, open in text mode, +, open for update (both reading and writing); S, optimize performance for sequential access; R, optimize performance for random access; D, file should be deleted when the last file descriptor is closed; T, optimize performance for short-lived temporary files.

stream 

Points to the stream to be mapped to a file descriptor.


RETURN VALUES

On failure, the freopen() and freopen64() functions return a null pointer, and errno is set to one of the following values:

EACCES 

Search permission is denied on a component of the path prefix, 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 interrupted the call.

EINVAL 

The value of the type argument is invalid.

EISDIR 

The named file is a directory, and type requires write access.

EMFILE 

Too many file descriptors are open in the calling process.

ENOENT 

A component of filename does not name an existing file, or filename is an empty string.

ENOMEM 

Insufficient storage space is available.

ENOSPC 

The directory or file system that would contain the new file cannot be expanded, the file does not exist and it was to be created.

ENOTDIR 

A component of the path prefix is not a directory.

EOVERFLOW 

The named file is a regular file and the size of the file cannot be represented correctly in an object of type off_t.

ETXTBSY 

The file is an executable that is in use, and type requires write access.


CONFORMANCE

ANSI/ISO 9899-1990 with exceptions.

freopen64(): Large File Specification, revision 1.5.


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

The modifiers D, T, R, S, and t are PTC MKS Toolkit UNIX APIs extensions, and are not guaranteed to be portable. If neither b nor t is specified, the determination of binary or text is made by examining the current state of the BINARY_OFLAG (see _NutConf() for details).


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
fclose(), fdopen(), fopen(), setbuf()

Miscellaneous:
lf64


PTC MKS Toolkit 10.2 Documentation Build 28.