SdFat
|
StdioStream implements a minimal stdio stream. More...
#include <StdioStream.h>
Public Member Functions | |
void | clearerr () |
int | fclose () |
int | feof () |
int | ferror () |
int | fflush () |
int | fgetc () |
char * | fgets (char *str, size_t num, size_t *len=0) |
bool | fopen (const char *path, const char *mode) |
int | fputc (int c) |
int | fputs (const char *str) |
size_t | fread (void *ptr, size_t size, size_t count) |
int | fseek (int32_t offset, int origin) |
int32_t | ftell () |
size_t | fwrite (const void *ptr, size_t size, size_t count) |
int | getc () |
size_t | print (char c) |
size_t | print (const char *str) |
size_t | print (const __FlashStringHelper *str) |
size_t | print (double val, uint8_t prec=2) |
size_t | print (float val, uint8_t prec=2) |
template<typename T > | |
size_t | print (T val) |
int | printDec (char n) |
int | printDec (signed char n) |
int | printDec (unsigned char n) |
int | printDec (int16_t n) |
int | printDec (uint16_t n) |
int | printDec (int32_t n) |
int | printDec (uint32_t n) |
int | printDec (double value, uint8_t prec) |
int | printDec (float value, uint8_t prec) |
int | printField (double value, char term, uint8_t prec=2) |
int | printField (float value, char term, uint8_t prec=2) |
template<typename T > | |
int | printField (T value, char term) |
int | printHex (uint32_t n) |
int | printHexln (uint32_t n) |
size_t | println () |
size_t | println (double val, uint8_t prec=2) |
size_t | println (float val, uint8_t prec=2) |
template<typename T > | |
size_t | println (T val) |
int | putc (int c) |
int | putCRLF () |
bool | rewind () |
StdioStream () | |
int | ungetc (int c) |
StdioStream implements a minimal stdio stream.
StdioStream does not support subdirectories or long file names.
|
inline |
Constructor
|
inline |
Clear the stream's end-of-file and error indicators.
int StdioStream::fclose | ( | ) |
Close a stream.
A successful call to the fclose function causes the stream to be flushed and the associated file to be closed. Any unwritten buffered data is written to the file; any unread buffered data is discarded. Whether or not the call succeeds, the stream is disassociated from the file.
Copyright (c) 2011-2019 Bill Greiman This file is part of the SdFat library for SD memory cards.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
inline |
Test the stream's end-of-file indicator.
|
inline |
Test the stream's error indicator.
int StdioStream::fflush | ( | ) |
Flush the stream.
If stream is an output stream or an update stream in which the most recent operation was not input, any unwritten data is written to the file; otherwise the call is an error since any buffered input data would be lost.
|
inline |
Get a byte from the stream.
char * StdioStream::fgets | ( | char * | str, |
size_t | num, | ||
size_t * | len = 0 |
||
) |
Get a string from a stream.
The fgets function reads at most one less than the number of characters specified by num from the stream into the array pointed to by str. No additional characters are read after a new-line character (which is retained) or after end-of-file. A null character is written immediately after the last character read into the array.
[out] | str | Pointer to an array of where the string is copied. |
[in] | num | Maximum number of characters including the null character. |
[out] | len | If len is not null and fgets is successful, the length of the string is returned. |
bool StdioStream::fopen | ( | const char * | path, |
const char * | mode | ||
) |
Open a stream.
Open a file and associates the stream with it.
[in] | path | file to be opened. |
[in] | mode | a string that indicates the open mode. |
"r" or "rb" | Open a file for reading. The file must exist. |
"w" or "wb" | Truncate an existing to zero length or create an empty file for writing. |
"wx" or "wbx" | Create a file for writing. Fails if the file already exists. |
"a" or "ab" | Append; open or create file for writing at end-of-file. |
"r+" or "rb+" or "r+b" | Open a file for update (reading and writing). |
"w+" or "w+b" or "wb+" | Truncate an existing to zero length or create a file for update. |
"w+x" or "w+bx" or "wb+x" | Create a file for update. Fails if the file already exists. |
"a+" or "a+b" or "ab+" | Append; open or create a file for update, writing at end-of-file. |
The character 'b' shall have no effect, but is allowed for ISO C standard conformance.
Opening a file with append mode causes all subsequent writes to the file to be forced to the then current end-of-file, regardless of intervening calls to the fseek function.
When a file is opened with update mode, both input and output may be performed on the associated stream. However, output shall not be directly followed by input without an intervening call to the fflush function or to a file positioning function (fseek, or rewind), and input shall not be directly followed by output without an intervening call to a file positioning function, unless the input operation encounters end-of-file.
|
inline |
Write a byte to a stream.
[in] | c | the byte to be written (converted to an unsigned char). |
int StdioStream::fputs | ( | const char * | str | ) |
Write a string to a stream.
[in] | str | a pointer to the string to be written. |
size_t StdioStream::fread | ( | void * | ptr, |
size_t | size, | ||
size_t | count | ||
) |
Binary input.
Reads an array of up to count elements, each one with a size of size bytes.
[out] | ptr | pointer to area of at least (size*count) bytes where the data will be stored. |
[in] | size | the size, in bytes, of each element to be read. |
[in] | count | the number of elements to be read. |
int StdioStream::fseek | ( | int32_t | offset, |
int | origin | ||
) |
Set the file position for the stream.
[in] | offset | number of offset from the origin. |
[in] | origin | position used as reference for the offset. It is specified by one of the following constants. |
SEEK_SET - Beginning of file.
SEEK_CUR - Current position of the file pointer.
SEEK_END - End of file.
int32_t StdioStream::ftell | ( | ) |
Get the current position in a stream.
size_t StdioStream::fwrite | ( | const void * | ptr, |
size_t | size, | ||
size_t | count | ||
) |
Binary output.
Writes an array of up to count elements, each one with a size of size bytes.
[in] | ptr | pointer to (size*count) bytes of data to be written. |
[in] | size | the size, in bytes, of each element to be written. |
[in] | count | the number of elements to be written. |
|
inline |
Get a byte from the stream.
getc and fgetc are equivalent but getc is in-line so it is faster but require more flash memory.
|
inline |
Write a character.
[in] | c | the character to write. |
|
inline |
Write a string.
[in] | str | the string to be written. |
size_t StdioStream::print | ( | const __FlashStringHelper * | str | ) |
Print a string stored in flash memory.
[in] | str | the string to print. |
|
inline |
Print a floating point number.
[in] | prec | Number of digits after decimal point. |
[in] | val | the number to be printed. |
|
inline |
Print a floating point number.
[in] | prec | Number of digits after decimal point. |
[in] | val | the number to be printed. |
|
inline |
Print a number.
[in] | val | the number to be printed. |
|
inline |
Print a char as a number.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | signed char | n | ) |
print a signed 8-bit integer
[in] | n | number to be printed. |
|
inline |
Print an unsigned 8-bit number.
[in] | n | number to be print. |
int StdioStream::printDec | ( | int16_t | n | ) |
Print a int16_t
[in] | n | number to be printed. |
int StdioStream::printDec | ( | uint16_t | n | ) |
print a uint16_t.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | int32_t | n | ) |
Print a signed 32-bit integer.
[in] | n | number to be printed. |
int StdioStream::printDec | ( | uint32_t | n | ) |
Write an unsigned 32-bit number.
[in] | n | number to be printed. |
|
inline |
Print a double.
[in] | value | The number to be printed. |
[in] | prec | Number of digits after decimal point. |
int StdioStream::printDec | ( | float | value, |
uint8_t | prec | ||
) |
Print a float.
[in] | value | The number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a number followed by a field terminator.
[in] | value | The number to be printed. |
[in] | term | The field terminator. |
int StdioStream::printHex | ( | uint32_t | n | ) |
Print HEX
[in] | n | number to be printed as HEX. |
|
inline |
Print HEX with CRLF
[in] | n | number to be printed as HEX. |
|
inline |
Write a CR/LF.
|
inline |
Print a floating point number followed by CR/LF.
[in] | val | the number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print a floating point number followed by CR/LF.
[in] | val | the number to be printed. |
[in] | prec | Number of digits after decimal point. |
|
inline |
Print an item followed by CR/LF
[in] | val | the item to be printed. |
|
inline |
Write a byte to a stream.
putc and fputc are equivalent but putc is in-line so it is faster but require more flash memory.
[in] | c | the byte to be written (converted to an unsigned char). |
|
inline |
Write a CR/LF.
bool StdioStream::rewind | ( | ) |
Set position of a stream to the beginning.
The rewind function sets the file position to the beginning of the file. It is equivalent to fseek(0L, SEEK_SET) except that the error indicator for the stream is also cleared.
int StdioStream::ungetc | ( | int | c | ) |
Push a byte back into an input stream.
[in] | c | the byte (converted to an unsigned char) to be pushed back. |
One character of push-back is guaranteed. If the ungetc function is called too many times without an intervening read or file positioning operation on that stream, the operation may fail.
A successful intervening call to a file positioning function (fseek, fsetpos, or rewind) discards any pushed-back characters for the stream.