diff options
| author | Sebastian Goll <sebastian.goll@gmx.de> | 2018-06-02 00:53:13 +0200 | 
|---|---|---|
| committer | Sebastian Goll <sebastian.goll@gmx.de> | 2018-06-02 00:56:12 +0200 | 
| commit | d40951182f051899acf66f11d55c526003b266c8 (patch) | |
| tree | 1a1cd508faaf775eadef05899f3342a973ba985c /printf.c | |
| parent | 0116b7491693306e613491b7ccc44743da6d60cb (diff) | |
| download | printf-d40951182f051899acf66f11d55c526003b266c8.tar.gz printf-d40951182f051899acf66f11d55c526003b266c8.tar.bz2 printf-d40951182f051899acf66f11d55c526003b266c8.zip | |
feat(printf): add user pointer to fctprintf()
Arbitrary user data can be passed to output function
Diffstat (limited to 'printf.c')
| -rw-r--r-- | printf.c | 19 | 
1 files changed, 11 insertions, 8 deletions
| @@ -77,6 +77,13 @@  typedef void (*out_fct_type)(char character, char* buffer, size_t idx, size_t maxlen);
 +// wrapper used as buffer
 +typedef struct {
 +  void (*fct)(char character, void* user);
 +  void* user;
 +} out_fct_wrap_type;
 +
 +
  // internal buffer output
  static inline void _out_buffer(char character, char* buffer, size_t idx, size_t maxlen)
  {
 @@ -105,10 +112,8 @@ static inline void _out_char(char character, char* buffer, size_t idx, size_t ma  static inline void _out_fct(char character, char* buffer, size_t idx, size_t maxlen)
  {
    (void)idx; (void)maxlen;
 -  typedef struct tag_out_fct_wrap_type {
 -    void (*fct)(char character);
 -  } out_fct_wrap_type;
 -  ((out_fct_wrap_type*)buffer)->fct(character);  // buffer is the output fct pointer
 +  // buffer is the output fct pointer
 +  ((out_fct_wrap_type*)buffer)->fct(character, ((out_fct_wrap_type*)buffer)->user);
  }
 @@ -691,13 +696,11 @@ int vsnprintf(char* buffer, size_t count, const char* format, va_list va)  }
 -int fctprintf(void (*out)(char character), const char* format, ...)
 +int fctprintf(void (*out)(char character, void* user), void* user, const char* format, ...)
  {
    va_list va;
    va_start(va, format);
 -  const struct tag_out_fct_wrap {
 -    void (*fct)(char character);
 -  } out_fct_wrap = { out };
 +  const out_fct_wrap_type out_fct_wrap = { out, user };
    const int ret = _vsnprintf(_out_fct, (char*)&out_fct_wrap, (size_t)-1, format, va);
    va_end(va);
    return ret;
 | 
