FILE
Defined in header <stdio.h>
|
||
typedef /* unspecified */ FILE; |
||
Each FILE
object denotes a C stream.
C standard does not specify whether FILE
is a complete object type. While it may be possible to copy a valid FILE
, using a pointer to such a copy as an argument for an I/O function invokes unspecified behavior. In other words, FILE
may be semantically non-copyable.
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 54 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Stream state
Besides the system-specific information necessary to access the device (e.g., a POSIX file descriptor), each FILE
object directly or indirectly holds the following:
- (哋它亢95) Character width: unset, narrow, or wide.
- (哋它亢95) Parse state for conversions between multibyte and wide characters (an object of type MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 52 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE)
- Buffering state: unbuffered, line-buffered, fully buffered.
- The buffer, which may be replaced by an external, user-provided buffer.
- I/O mode: input, output, or update (both input and output).
- Binary/text mode indicator.
- End-of-file status indicator.
- Error status indicator.
- File position indicator, accessible as an object of type MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 51 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE, which, for wide streams, includes parse state.
- (哋它亢11) Reentrant lock used to prevent data races when multiple threads read, write, position, or query the position of a stream.
Narrow and wide orientation
A newly opened stream has no orientation. The first call to fwide or to any I/O function establishes the orientation: a wide I/O function makes the stream wide-oriented; a narrow I/O function makes the stream narrow-oriented. Once set, the orientation can be changed with only MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 50 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE. Narrow I/O functions cannot be called on a wide-oriented stream; wide I/O functions cannot be called on a narrow-oriented stream. Wide I/O functions convert between wide and multibyte characters as if by calling MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 48 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE or MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 47 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE with the conversion state as described by the stream. Unlike the multibyte character strings that are valid in a program, multibyte character sequences in the file may contain embedded nulls and do not have to begin or end in the initial shift state.
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 46 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
Binary and text modes
A text stream is an ordered sequence of characters that can be composed into lines; a line can be decomposed into zero or more characters plus a terminating '\n' (“newline”) character. Whether the last line requires a terminating '\n' is implementation-defined. Furthermore, characters may have to be added, altered, or deleted on input and output to conform to the conventions for representing text in the OS (in particular, C streams on Windows OS convert '\n' to '\r\n' on output, and convert '\r\n' to '\n' on input).
MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 45 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE
- The data consist of only printing characters and/or the control characters '\t' and '\n' (in particular, on Windows OS, the character '\0x1A' terminates input).
- No '\n' character is immediately preceded by space characters (such space characters may disappear when such output is later read as input).
- The last character is '\n'.
A binary stream is an ordered sequence of characters that can transparently record internal data. Data read in from a binary stream always equal the data that were earlier written out to that stream, except that an implementation is allowed to append an indeterminate number of null characters to the end of the stream. A wide binary stream doesn't need to end in the initial shift state.
Notes
POSIX explicitly requires that the LC_CTYPE
facet of the currently installed C locale be stored within the FILE
object the moment the stream's orientation becomes wide; POSIX requires that this LC_CTYPE
facet be used for all future I/O on this stream until the orientation is changed, regardless of any subsequent call to MYMEMORY WARNING: YOU USED ALL AVAILABLE FREE TRANSLATIONS FOR TODAY. NEXT AVAILABLE IN 14 HOURS 03 MINUTES 44 SECONDS VISIT HTTPS://MYMEMORY.TRANSLATED.NET/DOC/USAGELIMITS.PHP TO TRANSLATE MORE.
It is intended that each line of text be composed of data that are essentially human-readable. POSIX implementations do not distinguish between text and binary streams (there is no special mapping for '\n' or any other characters).
References
- 哋它亢17 standard (ISO/IEC 9899:2018):
- 7.21 Input/output <stdio.h> (p: 217-247)
- 7.29 Extended multibyte and wide character utilities <wchar.h> (p: 295-325)
- 哋它亢11 standard (ISO/IEC 9899:2011):
- 7.21 Input/output <stdio.h> (p: 296-339)
- 7.29 Extended multibyte and wide character utilities <wchar.h> (p: 402-446)
- 哋它亢99 standard (ISO/IEC 9899:1999):
- 7.19 Input/output <stdio.h> (p: 262-305)
- 7.24 Extended multibyte and wide character utilities <wchar.h> (p: 348-392)
- 哋它亢89/C90 standard (ISO/IEC 9899:1990):
- 4.9 INPUT/OUTPUT <stdio.h>
See also
expression of type FILE* associated with the input stream expression of type FILE* associated with the output stream expression of type FILE* associated with the error output stream (macro constant) |