Стандарт языка Си С99 TC (1113411), страница 57
Текст из файла (страница 57)
After a successful fseek call, the nextoperation on an update stream may be either input or output.Returns6The fseek function returns nonzero only for a request that cannot be satisfied.Forward references: the ftell function (7.19.9.4).7.19.9.3 The fsetpos functionSynopsis1#include <stdio.h>int fsetpos(FILE *stream, const fpos_t *pos);Description2The fsetpos function sets the mbstate_t object (if any) and file position indicatorfor the stream pointed to by stream according to the value of the object pointed to bypos, which shall be a value obtained from an earlier successful call to the fgetposfunction on a stream associated with the same file.
If a read or write error occurs, theerror indicator for the stream is set and fsetpos fails.3A successful call to the fsetpos function undoes any effects of the ungetc functionon the stream, clears the end-of-file indicator for the stream, and then establishes the newparse state and position.
After a successful fsetpos call, the next operation on anupdate stream may be either input or output.Returns4If successful, the fsetpos function returns zero; on failure, the fsetpos functionreturns nonzero and stores an implementation-defined positive value in errno.7.19.9.4 The ftell functionSynopsis1#include <stdio.h>long int ftell(FILE *stream);Description2The ftell function obtains the current value of the file position indicator for the streampointed to by stream. For a binary stream, the value is the number of characters fromthe beginning of the file. For a text stream, its file position indicator contains unspecifiedinformation, usable by the fseek function for returning the file position indicator for thestream to its position at the time of the ftell call; the difference between two suchreturn values is not necessarily a meaningful measure of the number of characters written§7.19.9.4Library303ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N1256or read.Returns3If successful, the ftell function returns the current value of the file position indicatorfor the stream.
On failure, the ftell function returns −1L and stores animplementation-defined positive value in errno.7.19.9.5 The rewind functionSynopsis1#include <stdio.h>void rewind(FILE *stream);Description2The rewind function sets the file position indicator for the stream pointed to bystream to the beginning of the file. It is equivalent to(void)fseek(stream, 0L, SEEK_SET)except that the error indicator for the stream is also cleared.Returns3The rewind function returns no value.7.19.10 Error-handling functions7.19.10.1 The clearerr functionSynopsis1#include <stdio.h>void clearerr(FILE *stream);Description2The clearerr function clears the end-of-file and error indicators for the stream pointedto by stream.Returns3The clearerr function returns no value.304Library§7.19.10.1WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC37.19.10.2 The feof functionSynopsis1#include <stdio.h>int feof(FILE *stream);Description2The feof function tests the end-of-file indicator for the stream pointed to by stream.Returns3The feof function returns nonzero if and only if the end-of-file indicator is set forstream.7.19.10.3 The ferror functionSynopsis1#include <stdio.h>int ferror(FILE *stream);Description2The ferror function tests the error indicator for the stream pointed to by stream.Returns3The ferror function returns nonzero if and only if the error indicator is set forstream.7.19.10.4 The perror functionSynopsis1#include <stdio.h>void perror(const char *s);Description2The perror function maps the error number in the integer expression errno to anerror message.
It writes a sequence of characters to the standard error stream thus: first(if s is not a null pointer and the character pointed to by s is not the null character), thestring pointed to by s followed by a colon (:) and a space; then an appropriate errormessage string followed by a new-line character. The contents of the error messagestrings are the same as those returned by the strerror function with argument errno.Returns3The perror function returns no value.Forward references: the strerror function (7.21.6.2).§7.19.10.4Library305ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.20 General utilities <stdlib.h>1The header <stdlib.h> declares five types and several functions of general utility, anddefines several macros.257)2The types declared are size_t and wchar_t (both described in 7.17),div_twhich is a structure type that is the type of the value returned by the div function,ldiv_twhich is a structure type that is the type of the value returned by the ldiv function, andlldiv_twhich is a structure type that is the type of the value returned by the lldiv function.3The macros defined are NULL (described in 7.17);EXIT_FAILUREandEXIT_SUCCESSwhich expand to integer constant expressions that can be used as the argument to theexit function to return unsuccessful or successful termination status, respectively, to thehost environment;RAND_MAXwhich expands to an integer constant expression that is the maximum value returned bythe rand function; andMB_CUR_MAXwhich expands to a positive integer expression with type size_t that is the maximumnumber of bytes in a multibyte character for the extended character set specified by thecurrent locale (category LC_CTYPE), which is never greater than MB_LEN_MAX.257) See ‘‘future library directions’’ (7.26.10).306Library§7.20WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC37.20.1 Numeric conversion functions1The functions atof, atoi, atol, and atoll need not affect the value of the integerexpression errno on an error.
If the value of the result cannot be represented, thebehavior is undefined.7.20.1.1 The atof functionSynopsis1#include <stdlib.h>double atof(const char *nptr);Description2The atof function converts the initial portion of the string pointed to by nptr todouble representation. Except for the behavior on error, it is equivalent tostrtod(nptr, (char **)NULL)Returns3The atof function returns the converted value.Forward references: the strtod, strtof, and strtold functions (7.20.1.3).7.20.1.2 The atoi, atol, and atoll functionsSynopsis1#include <stdlib.h>int atoi(const char *nptr);long int atol(const char *nptr);long long int atoll(const char *nptr);Description2The atoi, atol, and atoll functions convert the initial portion of the string pointedto by nptr to int, long int, and long long int representation, respectively.Except for the behavior on error, they are equivalent toatoi: (int)strtol(nptr, (char **)NULL, 10)atol: strtol(nptr, (char **)NULL, 10)atoll: strtoll(nptr, (char **)NULL, 10)Returns3The atoi, atol, and atoll functions return the converted value.Forward references: the strtol, strtoll, strtoul, and strtoull functions(7.20.1.4).§7.20.1.2Library307ISO/IEC 9899:TC3Committee Draft — Septermber 7, 2007WG14/N12567.20.1.3 The strtod, strtof, and strtold functionsSynopsis1#include <stdlib.h>double strtod(const char * restrict nptr,char ** restrict endptr);float strtof(const char * restrict nptr,char ** restrict endptr);long double strtold(const char * restrict nptr,char ** restrict endptr);Description2The strtod, strtof, and strtold functions convert the initial portion of the stringpointed to by nptr to double, float, and long double representation,respectively.
First, they decompose the input string into three parts: an initial, possiblyempty, sequence of white-space characters (as specified by the isspace function), asubject sequence resembling a floating-point constant or representing an infinity or NaN;and a final string of one or more unrecognized characters, including the terminating nullcharacter of the input string. Then, they attempt to convert the subject sequence to afloating-point number, and return the result.3The expected form of the subject sequence is an optional plus or minus sign, then one ofthe following:— a nonempty sequence of decimal digits optionally containing a decimal-pointcharacter, then an optional exponent part as defined in 6.4.4.2;— a 0x or 0X, then a nonempty sequence of hexadecimal digits optionally containing adecimal-point character, then an optional binary exponent part as defined in 6.4.4.2;— INF or INFINITY, ignoring case— NAN or NAN(n-char-sequenceopt), ignoring case in the NAN part, where:n-char-sequence:digitnondigitn-char-sequence digitn-char-sequence nondigitThe subject sequence is defined as the longest initial subsequence of the input string,starting with the first non-white-space character, that is of the expected form.
The subjectsequence contains no characters if the input string is not of the expected form.4If the subject sequence has the expected form for a floating-point number, the sequence ofcharacters starting with the first digit or the decimal-point character (whichever occursfirst) is interpreted as a floating constant according to the rules of 6.4.4.2, except that the308Library§7.20.1.3WG14/N1256Committee Draft — Septermber 7, 2007ISO/IEC 9899:TC3decimal-point character is used in place of a period, and that if neither an exponent partnor a decimal-point character appears in a decimal floating point number, or if a binaryexponent part does not appear in a hexadecimal floating point number, an exponent partof the appropriate type with value zero is assumed to follow the last digit in the string.
Ifthe subject sequence begins with a minus sign, the sequence is interpreted as negated.258)A character sequence INF or INFINITY is interpreted as an infinity, if representable inthe return type, else like a floating constant that is too large for the range of the returntype. A character sequence NAN or NAN(n-char-sequenceopt), is interpreted as a quietNaN, if supported in the return type, else like a subject sequence part that does not havethe expected form; the meaning of the n-char sequences is implementation-defined.259) Apointer to the final string is stored in the object pointed to by endptr, provided thatendptr is not a null pointer.5If the subject sequence has the hexadecimal form and FLT_RADIX is a power of 2, thevalue resulting from the conversion is correctly rounded.6In other than the "C" locale, additional locale-specific subject sequence forms may beaccepted.7If the subject sequence is empty or does not have the expected form, no conversion isperformed; the value of nptr is stored in the object pointed to by endptr, providedthat endptr is not a null pointer.Recommended practice8If the subject sequence has the hexadecimal form, FLT_RADIX is not a power of 2, andthe result is not exactly representable, the result should be one of the two numbers in theappropriate internal format that are adjacent to the hexadecimal floating source value,with the extra stipulation that the error should have a correct sign for the current roundingdirection.9If the subject sequence has the decimal form and at most DECIMAL_DIG (defined in<float.h>) significant digits, the result should be correctly rounded.