Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add include guards to printf library #8

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions external/printf/printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
}
}

#ifndef PRINTF_VOXLESS
// evaluate length field
switch (*format) {
case 'l' :
Expand All @@ -653,6 +654,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
format++;
}
break;

case 'h' :
flags |= FLAGS_SHORT;
format++;
Expand All @@ -661,6 +663,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
format++;
}
break;

#if defined(PRINTF_SUPPORT_PTRDIFF_T)
case 't' :
flags |= (sizeof(ptrdiff_t) == sizeof(long) ? FLAGS_LONG : FLAGS_LONG_LONG);
Expand All @@ -678,6 +681,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
default :
break;
}
#endif // PRINTF_VOXLESS

// evaluate specifier
switch (*format) {
Expand Down Expand Up @@ -754,6 +758,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
format++;
break;
}

#if defined(PRINTF_SUPPORT_FLOAT)
case 'f' :
case 'F' :
Expand Down Expand Up @@ -818,7 +823,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
format++;
break;
}

#ifndef PRINTF_VOXLESS
case 'p' : {
width = sizeof(void*) * 2U;
flags |= FLAGS_ZEROPAD | FLAGS_UPPERCASE;
Expand All @@ -836,7 +841,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const
format++;
break;
}

#endif // PRINTF_VOXLESS
case '%' :
out('%', buffer, idx++, maxlen);
format++;
Expand All @@ -858,7 +863,7 @@ static int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const


///////////////////////////////////////////////////////////////////////////////

#ifndef PRINTF_VOXLESS
int printf_(const char* format, ...)
{
va_list va;
Expand All @@ -868,7 +873,7 @@ int printf_(const char* format, ...)
va_end(va);
return ret;
}

#endif

int sprintf_(char* buffer, const char* format, ...)
{
Expand All @@ -889,20 +894,21 @@ int snprintf_(char* buffer, size_t count, const char* format, ...)
return ret;
}


#ifndef PRINTF_VOXLESS
int vprintf_(const char* format, va_list va)
{
char buffer[1];
return _vsnprintf(_out_char, buffer, (size_t)-1, format, va);
}
#endif


int vsnprintf_(char* buffer, size_t count, const char* format, va_list va)
{
return _vsnprintf(_out_buffer, buffer, count, format, va);
}


#ifndef PRINTF_VOXLESS
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...)
{
va_list va;
Expand All @@ -912,3 +918,4 @@ int fctprintf(void (*out)(char character, void* arg), void* arg, const char* for
va_end(va);
return ret;
}
#endif
8 changes: 4 additions & 4 deletions external/printf/printf.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern "C" {
*/
void _putchar(char character);


#ifndef PRINTF_VOXLESS
/**
* Tiny printf implementation
* You have to implement _putchar if you use printf()
Expand All @@ -59,7 +59,7 @@ void _putchar(char character);
*/
#define printf printf_
int printf_(const char* format, ...);

#endif

/**
* Tiny sprintf implementation
Expand Down Expand Up @@ -88,6 +88,7 @@ int snprintf_(char* buffer, size_t count, const char* format, ...);
int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);


#ifndef PRINTF_VOXLESS
/**
* Tiny vprintf implementation
* \param format A string that specifies the format of the output
Expand All @@ -97,7 +98,6 @@ int vsnprintf_(char* buffer, size_t count, const char* format, va_list va);
#define vprintf vprintf_
int vprintf_(const char* format, va_list va);


/**
* printf with output function
* You may use this as dynamic alternative to printf() with its fixed _putchar() output
Expand All @@ -107,7 +107,7 @@ int vprintf_(const char* format, va_list va);
* \return The number of characters that are sent to the output function, not counting the terminating null character
*/
int fctprintf(void (*out)(char character, void* arg), void* arg, const char* format, ...);

#endif

#ifdef __cplusplus
}
Expand Down
1 change: 1 addition & 0 deletions printf_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
#define PRINTF_DISABLE_SUPPORT_EXPONENTIAL
#define PRINTF_DISABLE_SUPPORT_PTRDIFF_T
#define PRINTF_DISABLE_SUPPORT_FLOAT
#define PRINTF_VOXLESS