Include | #include <stdio.h> |
---|---|
Header | {z88dk}/include/_DEVELOPMENT/sccz80/stdio.h |
{z88dk}/include/_DEVELOPMENT/sdcc/stdio.h | |
Source | {z88dk}/libsrc/_DEVELOPMENT/stdio |
All functions are re-entrant.
Some text taken from these references:
Not available until disk i/o is added.
Open and close are present but not complete until disk i/o is added.
Associate a stream with the low-level file descriptor. Closing the returned FILE will also close the underlying fd.
mode is a character string indicating how the file will be used. Its meaning is exactly as specified in fopen() except that modes containing “w” will not cause file truncation.
If an error occurs, 0 will be returned with the carry flag set and errno will be set to one of:
Return the integer file descriptor associated with stream.
If an error occurs, -1 will be returned with the carry flag set and errno will be set to one of:
Reads from stream under the control of the format string and assigns converted values to subsequent arguments, each of which must be a pointer. It returns when format is exhausted or an error occurs. fscanf returns -1 if no characters could be read from the stream. Otherwise it returns the number of conversions performed and assigned.
The format string usually contains conversion specifications which are used to direct interpretation of input. The format string may contain:
A conversion specification determines how the next bytes on the stream are interpreted. Normally the result is placed in the variable pointed to by the next argument in the argument list. If assignment suppression is indicated by *, as in %*s, the input field is read from the stream but no assignment is made. An input field is defined as a string of non-whitespace characters; it extends until the next whitespace character or until the field width, if specified, is exhausted. This implies that scanf will read across line boundaries to find its input since newlines are considered whitespace.
The following length modifiers are accepted: hh, h, l, ll, j, z, t, L but only “l” has meaning for converters “Bdinopux” and (sdcc only) “ll” for converters “dioux”.
The conversion character indicates how the input field is interpreted. The conversion characters are listed below:
CHARACTER | STREAM CHARACTERS | ASSIGNED TO |
---|---|---|
B | binary number | uint16_t * |
c | characters 4 | char * |
d | decimal number | int16_t * |
i | number 1 | int16_t * |
I | IPv4 Address in dotted form 1 | uint32_t * |
n | (no stream chars) number of chars read thus far | uint16_t * |
o | octal number 2 | uint16_t * |
p | pointer | void * * |
s | characters 8 | char * |
[..] | characters 5 | char * |
[^..] | characters 6 | char * |
u | unsigned decimal number | uint16_t * |
x | hexadecimal number 3 | uint16_t * |
lB | binary number | uint32_t * |
ld | decimal number | int32_t * |
li | number 1 | int32_t * |
ln | (no stream chars) number of chars read thus far | uint32_t * |
lo | octal number 2 | uint32_t * |
lp | pointer | uint32_t * |
lu | unsigned decimal number | uint32_t * |
lx | hexadecimal number 3 | uint32_t * |
lld | decimal number | int64_t * |
lli | number 1 | int64_t * |
llo | octal number 2 | uint64_t * |
llu | unsigned decimal number | uint64_t * |
llx | hexadecimal number 3 | uint64_t * |
% | match % from stream | no assignment made |
1 may be in octal (leading 0), decimal or hexadecimal (leading 0x)
2 with or without leading 0
3 with or without leading 0x
4 chars are written to the array up to the width (default=1) specified, whitespace is not skipped
5 matches longest non-empty string of chars from stream in the set, terminating '\0' is added
6 matches longest non-empty string of chars from stream not in the set, terminating '\0' is added
8 leading whitespace is skipped then characters are read until the next whitespace char
NOTE: Some or all of these converters may be disabled by the target's library config file. Floating point converters “aefg” have not been added yet but string to float conversion can also be done with strtod and atof. One method to read floats would be to first scan them as a string using %[ and then using one of the aforementioned functions to convert the string to a float.
If an error occurs, the carry flag is set and errno will be set to:
The device driver may set other errors. errno is not set if there is a character mismatch with the format string.
Writes formatted output to stream under the control of the format string using data from arguments following format. Returns the number of characters written or -1 if an error occurs.
The format string contains two types of objects: ordinary characters, which are copied to the output stream, and conversion specifiers, each of which causes the next argument of fprintf to be output to the stream in the manner specified. Each conversion specifier begins with % and ends with a conversion character. Between the % and the conversion character there may be optional modifiers, in order:
If the width or precision is '*', their value is taken from an int argument in the parameter list. A negative field width argument is taken as a '-' flag followed by a positive field width. A negative precision argument is taken as if the precision were omitted.
Finally, the conversion characters and their meanings are shown below. If the character after % is not listed below, EINVAL is returned.
CHARACTER | ARGUMENT TYPE | CONVERTED TO |
---|---|---|
B | uint16_t | unsigned binary |
c | char | single character |
d,i | int16_t | signed decimal |
I | uint32_t | IPv4 address in dotted decimal form |
n | uint16_t * | number of characters output so far is written into the argument |
o | int16_t | unsigned octal |
p,P | void * | pointer, P uses capitals |
s | char * | string of characters up to \0 or until precision exhausted |
u | uint16_t | unsigned decimal |
x,X | uint16_t | unsigned hexadecimal, X uses capitals |
lB | uint32_t | unsigned binary |
ld,li | int32_t | signed decimal |
lo | uint32_t | unsigned octal |
lu | uint32_t | unsigned decimal |
lx,lX | uint32_t | unsigned hexadecimal, X uses capitals |
lp,lP | uint32_t | pointer, P uses capitals |
lld,lli | int64_t | signed decimal |
llo | uint64_t | unsigned octal |
llu | uint64_t | unsigned decimal |
llx,llX | uint64_t | unsigned hexadecimal, X uses capitals |
a,A | double/float | double in hex format +-h.hhhp+-d |
e,E | double/float | double in exp format +-d.ddde+-d |
f,F | double/float | double in format +-ddd.ddd |
g,G | double/float | chooses either e or f for best looking result |
% | none | output a % |
NOTE: Some or all of these converters may be disabled by the target's library config file. Float to text conversion can also be performed by dtoa and family.
If an error occurs, -(# chars output + 1) is returned with the carry flag set and errno set to:
The underlying device driver may set errno to other values.