diff options
author | Marco Paland <marco@paland.com> | 2018-05-15 12:14:51 +0200 |
---|---|---|
committer | Marco Paland <marco@paland.com> | 2018-05-15 12:14:51 +0200 |
commit | 24c460b977c014076821a36b2dae574893cebb85 (patch) | |
tree | 9308d0871a9dbf727392ac1bf2390c1e1906c3ac /printf.c | |
parent | d12e52be4c207bb3b8a35f512b2cddf8deb3ceaf (diff) | |
download | printf-24c460b977c014076821a36b2dae574893cebb85.tar.gz printf-24c460b977c014076821a36b2dae574893cebb85.tar.bz2 printf-24c460b977c014076821a36b2dae574893cebb85.zip |
feat(printf): added new oprintf() function
Write formatted output directly to given output function
Diffstat (limited to 'printf.c')
-rw-r--r-- | printf.c | 20 |
1 files changed, 19 insertions, 1 deletions
@@ -101,6 +101,14 @@ static inline void _out_char(char character, char* buffer, size_t idx, size_t ma }
+// internal output function wrapper
+static inline void _out_fct(char character, char* buffer, size_t idx, size_t maxlen)
+{
+ (void)idx; (void)maxlen;
+ ((void (*)(char character))buffer)(character); // buffer is the output fct pointer
+}
+
+
// internal strlen
// \return The length of the string (excluding the terminating 0)
static inline unsigned int _strlen(const char* str)
@@ -674,7 +682,17 @@ int snprintf(char* buffer, size_t count, const char* format, ...) }
-inline int vsnprintf(char* buffer, size_t count, const char* format, va_list va)
+int vsnprintf(char* buffer, size_t count, const char* format, va_list va)
{
return _vsnprintf(_out_buffer, buffer, count, format, va);
}
+
+
+int oprintf(void (*out)(char character), const char* format, ...)
+{
+ va_list va;
+ va_start(va, format);
+ const int ret = _vsnprintf(_out_fct, (char*)out, (size_t)-1, format, va);
+ va_end(va);
+ return ret;
+}
|