libc/minimal: Create "real" functions for putc and putchar

When gcc is building without -fno-builtin, it will optimize calls like
printf("\n") into a call to putchar('\n'), but it won't use a static inline
in that case, instead insisting on a real function.

To make this a bit easier, adopt the usual C library practice of making
putc and putchar macros instead of static inline functions. There's no loss
of typechecking as the parameters are directly passed to underlying
functions with the same parameter types.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2023-04-20 12:54:26 -07:00 committed by Christopher Friedt
parent 4fab10d0a1
commit 27b7ace9fd
2 changed files with 14 additions and 8 deletions

View file

@ -60,14 +60,8 @@ int fputc(int c, FILE *stream);
int fputs(const char *ZRESTRICT s, FILE *ZRESTRICT stream);
size_t fwrite(const void *ZRESTRICT ptr, size_t size, size_t nitems,
FILE *ZRESTRICT stream);
static inline int putc(int c, FILE *stream)
{
return fputc(c, stream);
}
static inline int putchar(int c)
{
return putc(c, stdout);
}
#define putc(c, stream) fputc(c, stream)
#define putchar(c) putc(c, stdout)
#ifdef __cplusplus
}

View file

@ -53,6 +53,18 @@ int fputs(const char *ZRESTRICT s, FILE *ZRESTRICT stream)
return len == ret ? 0 : EOF;
}
#undef putc
int putc(int c, FILE *stream)
{
return zephyr_fputc(c, stream);
}
#undef putchar
int putchar(int c)
{
return zephyr_fputc(c, stdout);
}
size_t z_impl_zephyr_fwrite(const void *ZRESTRICT ptr, size_t size,
size_t nitems, FILE *ZRESTRICT stream)
{