tools

various tools
git clone git://deadbeef.fr/tools.git
Log | Files | Refs | README | LICENSE

commit 7719829ee0a638698cfd2cb92effeec519f47949
parent c8ff0d45255189901ef41775368c4d7ec4ffb298
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date:   Thu,  3 Dec 2020 17:27:00 +0100

adds ungets(), based on ungetc()

Diffstat:
Mbtl/src/utils.cpp | 13+++++++++++++
Mbtl/src/utils.hpp | 4++++
2 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/btl/src/utils.cpp b/btl/src/utils.cpp @@ -78,3 +78,16 @@ int esc_fputs( const char *s, FILE *stream ) } while( chunk_start != str_end ); return 0; } + +int ungets( char const* const str, size_t str_sz ) +{ + // reverse push, since otherwise one would start with EOF + for( size_t i = str_sz; i; --i ) + { + if( EOF == ungetc( str[i-1], stdin ) ) + { + return i; + } + } + return 0; +} diff --git a/btl/src/utils.hpp b/btl/src/utils.hpp @@ -67,4 +67,8 @@ inline bool empty_array( T* arr ) //returns 0 on success, INT_MAX on error int esc_fputs( const char *s, FILE *stream ); +// prints a string into stdin for further reading. Might not +// be null-terminated. +inline int ungets( char const* const str, size_t str_sz ); + #endif