Стандарт языка Си С99 TC (1113411), страница 48
Текст из файла (страница 48)
The macro UINTN_C(value) shall expandto an integer constant expression corresponding to the type uint_leastN_t. Forexample, if uint_least64_t is a name for the type unsigned long long int,then UINT64_C(0x123) might expand to the integer constant 0x123ULL.7.18.4.2 Macros for greatest-width integer constants1The following macro expands to an integer constant expression having the value specifiedby its argument and the type intmax_t:INTMAX_C(value)The following macro expands to an integer constant expression having the value specifiedby its argument and the type uintmax_t:UINTMAX_C(value)§7.18.4.2Library261ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.19 Input/output <stdio.h>7.19.1 Introduction1The header <stdio.h> declares three types, several macros, and many functions forperforming input and output.2The types declared are size_t (described in 7.17);FILEwhich is an object type capable of recording all the information needed to control astream, including its file position indicator, a pointer to its associated buffer (if any), anerror indicator that records whether a read/write error has occurred, and an end-of-fileindicator that records whether the end of the file has been reached; andfpos_twhich is an object type other than an array type capable of recording all the informationneeded to specify uniquely every position within a file.3The macros are NULL (described in 7.17);_IOFBF_IOLBF_IONBFwhich expand to integer constant expressions with distinct values, suitable for use as thethird argument to the setvbuf function;BUFSIZwhich expands to an integer constant expression that is the size of the buffer used by thesetbuf function;EOFwhich expands to an integer constant expression, with type int and a negative value, thatis returned by several functions to indicate end-of-file, that is, no more input from astream;FOPEN_MAXwhich expands to an integer constant expression that is the minimum number of files thatthe implementation guarantees can be open simultaneously;FILENAME_MAXwhich expands to an integer constant expression that is the size needed for an array ofchar large enough to hold the longest file name string that the implementation262Library§7.19.1WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3guarantees can be opened;231)L_tmpnamwhich expands to an integer constant expression that is the size needed for an array ofchar large enough to hold a temporary file name string generated by the tmpnamfunction;SEEK_CURSEEK_ENDSEEK_SETwhich expand to integer constant expressions with distinct values, suitable for use as thethird argument to the fseek function;TMP_MAXwhich expands to an integer constant expression that is the maximum number of uniquefile names that can be generated by the tmpnam function;stderrstdinstdoutwhich are expressions of type ‘‘pointer to FILE’’ that point to the FILE objectsassociated, respectively, with the standard error, input, and output streams.4The header <wchar.h> declares a number of functions useful for wide character inputand output.
The wide character input/output functions described in that subclauseprovide operations analogous to most of those described here, except that thefundamental units internal to the program are wide characters. The externalrepresentation (in the file) is a sequence of ‘‘generalized’’ multibyte characters, asdescribed further in 7.19.3.5The input/output functions are given the following collective terms:— The wide character input functions — those functions described in 7.24 that performinput into wide characters and wide strings: fgetwc, fgetws, getwc, getwchar,fwscanf, wscanf, vfwscanf, and vwscanf.— The wide character output functions — those functions described in 7.24 that performoutput from wide characters and wide strings: fputwc, fputws, putwc,putwchar, fwprintf, wprintf, vfwprintf, and vwprintf.231) If the implementation imposes no practical limit on the length of file name strings, the value ofFILENAME_MAX should instead be the recommended size of an array intended to hold a file namestring.
Of course, file name string contents are subject to other system-specific constraints; thereforeall possible strings of length FILENAME_MAX cannot be expected to be opened successfully.§7.19.1Library263ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256— The wide character input/output functions — the union of the ungetwc function, thewide character input functions, and the wide character output functions.— The byte input/output functions — those functions described in this subclause thatperform input/output: fgetc, fgets, fprintf, fputc, fputs, fread,fscanf, fwrite, getc, getchar, gets, printf, putc, putchar, puts,scanf, ungetc, vfprintf, vfscanf, vprintf, and vscanf.Forward references: files (7.19.3), the fseek function (7.19.9.2), streams (7.19.2), thetmpnam function (7.19.4.4), <wchar.h> (7.24).7.19.2 Streams1Input and output, whether to or from physical devices such as terminals and tape drives,or whether to or from files supported on structured storage devices, are mapped intological data streams, whose properties are more uniform than their various inputs andoutputs.
Two forms of mapping are supported, for text streams and for binarystreams.232)2A text stream is an ordered sequence of characters composed into lines, each lineconsisting of zero or more characters plus a terminating new-line character. Whether thelast line requires a terminating new-line character is implementation-defined.
Charactersmay have to be added, altered, or deleted on input and output to conform to differingconventions for representing text in the host environment. Thus, there need not be a oneto-one correspondence between the characters in a stream and those in the externalrepresentation. Data read in from a text stream will necessarily compare equal to the datathat were earlier written out to that stream only if: the data consist only of printingcharacters and the control characters horizontal tab and new-line; no new-line character isimmediately preceded by space characters; and the last character is a new-line character.Whether space characters that are written out immediately before a new-line characterappear when read in is implementation-defined.3A binary stream is an ordered sequence of characters that can transparently recordinternal data.
Data read in from a binary stream shall compare equal to the data that wereearlier written out to that stream, under the same implementation. Such a stream may,however, have an implementation-defined number of null characters appended to the endof the stream.4Each stream has an orientation. After a stream is associated with an external file, butbefore any operations are performed on it, the stream is without orientation. Once a widecharacter input/output function has been applied to a stream without orientation, the232) An implementation need not distinguish between text streams and binary streams. In such animplementation, there need be no new-line characters in a text stream nor any limit to the length of aline.264Library§7.19.2WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3stream becomes a wide-oriented stream. Similarly, once a byte input/output function hasbeen applied to a stream without orientation, the stream becomes a byte-oriented stream.Only a call to the freopen function or the fwide function can otherwise alter theorientation of a stream.
(A successful call to freopen removes any orientation.)233)5Byte input/output functions shall not be applied to a wide-oriented stream and widecharacter input/output functions shall not be applied to a byte-oriented stream. Theremaining stream operations do not affect, and are not affected by, a stream’s orientation,except for the following additional restrictions:— Binary wide-oriented streams have the file-positioning restrictions ascribed to bothtext and binary streams.— For wide-oriented streams, after a successful call to a file-positioning function thatleaves the file position indicator prior to the end-of-file, a wide character outputfunction can overwrite a partial multibyte character; any file contents beyond thebyte(s) written are henceforth indeterminate.6Each wide-oriented stream has an associated mbstate_t object that stores the currentparse state of the stream.