INtime SDK Help
fdopen

Opens a stream associated with a file descriptor, allowing a file opened for low-level I/O to be buffered and formatted.

#include <stdio.h>

FILE *fdopen(int handle, char *mode);

#include <wchar.h>

FILE *_wfdopen(int handle, const wchar_t *mode);

Parameters

handle
Descriptor referring to an open file.
mode
Specifies the open mode (type of access permitted) for the file.

Remarks

This list gives the mode string, including required quotes, as used in fdopen. It also relates the mode string and the corresponding oflag arguments used in sopen.

Value Description
"r" Opens for reading. If the file does not exist or cannot be found, the call will fail. Relates to O_RDONLY.
"w" Opens an empty file for writing. If the given file exists, its contents are destroyed. Relates to O_WRONLY (usually O_WRONLY | O_CREAT | O_TRUNC).
"a" Opens for writing at the end of the file (appending); creates the file first if it doesn't exist. Relates to O_WRONLY | O_APPEND (usually O_WRONLY | O_CREAT | O_APPEND).
"r+" Opens for both reading and writing. The file must exist. Relates to O_RDWR.
"w+" Opens an empty file for both reading and writing. If the given file exists, its contents are destroyed. Relates to O_RDWR (usually O_RDWR | O_CREAT | O_TRUNC).
"a+" Opens for reading and appending; creates the file first if it doesn't exist. Relates to O_RDWR | O_APPEND (usually O_RDWR | O_APPEND | O_CREAT).

Use the "w" and "w+" types with care, as they can destroy existing files.

When a file is opened with the "a" or "a+" open mode, all write operations occur at the end of the file, even if you've repositioned the file pointer using fseek or rewind. Thus, existing data cannot be overwritten.

When the "r+", "w+", or "a+" open mode is specified, both reading and writing are allowed (the file is open for update). However, when you switch between reading and writing, there must be an intervening rewind operation or fsetpos or fseek, which can reposition the file pointer, if desired.

In addition to these values, one of these characters can be included after mode but between the quotation marks to specify the translation mode for <LF> characters. The t and b characters correspond to the constants used in open and sopen, as listed below.

Value Description
t Open in text (translated) mode. <CR><LF> combinations are translated into single <LF> characters on input and <LF> characters are translated to <CR><LF> combinations on output.

<Ctrl-Z> is interpreted as an end-of-file character on input. In files opened for reading or for reading/writing, checks for and removes <Ctrl-Z> if possible, because <Ctrl-Z> may cause fseek to behave improperly near the end of the file. Relates to O_TEXT.

b Open in binary (untranslated) mode; the above translations are suppressed. Relates to O_BINARY.
c Set commit mode so that the contents of a file buffer are flushed to disk if fflush or fclose is called, or if fflush is called implicitly as the result of writing a file stream.
           

_wfdopen is the wide-character version of fdopen.

Streams are opened by default with no orientation. The oreintation is set on the first operation on the stream. For example if the first operation is a single-byte read or write then the stream becomes a byte-oriented stream. If the first operation is a wide-character read or write then the stream becomes a wide-oriented stream. Only a call to freopen or fwide can otherwise alter the orientation of a stream. A stream can be set to wide-orientation on opening by means of the non-standard "ccs=UNICODE" mode.

Return Values

A pointer to the open stream.
Success.
A null pointer on error, such as t or b appearing before mode.
Failure.

Generic Text Routines

tchar.h routine _UNICODE not defined _UNICODE defined
_tfdopen fdopen _wfdopen

Requirements

Versions Defined in Include Link to
INtime 3.0
INtime 6.0 (wide-character and generic text versions)
intime/rt/include/stdio.h
intime/rt/include/wchar.h
intime/rt/include/tchar.h
stdio.h
wchar.h
tchar.h
clib.lib
See Also