refactor: libc - share printf, split the float path, fix relink deps
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* printf_internal.h
|
||||
* Shared state between the integer printf core (libc.c) and the optional
|
||||
* floating-point conversion module (printf_float.c).
|
||||
* Copyright (c) 2026 Daniel Hammer
|
||||
*/
|
||||
|
||||
#ifndef _LIBC_PRINTF_INTERNAL_H
|
||||
#define _LIBC_PRINTF_INTERNAL_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/* Output cursor shared by every conversion. `pos` counts the characters a
|
||||
conversion WOULD have written, so it may run past `max`; only writes below
|
||||
`max` land in `buf`. That is what gives snprintf its C99 return value. */
|
||||
struct _pf_state {
|
||||
char *buf;
|
||||
size_t pos;
|
||||
size_t max;
|
||||
};
|
||||
|
||||
/* Defined in libc.c. External rather than static so the float module can
|
||||
reach it; it is the only core helper the float conversions need. */
|
||||
void _pf_putc(struct _pf_state *st, char c);
|
||||
|
||||
/* Union for double bit manipulation (used by float formatting and math). */
|
||||
typedef union { double d; uint64_t u; } _dbl_bits;
|
||||
|
||||
/* Defined in printf_float.c, which is a SEPARATE archive member so that
|
||||
--gc-sections can drop the decimal-conversion and pow/exp/log code from
|
||||
programs that never format a float. vsnprintf calls this through a WEAK
|
||||
reference: link with -Wl,-u,_pf_putfloat to pull the module in. Without
|
||||
that flag %e/%f/%g echo their conversion spec instead of a number. */
|
||||
void _pf_putfloat(struct _pf_state *st, double v, char conv,
|
||||
int precision, int width, char pad,
|
||||
int left_align, int plus, int space, int alt);
|
||||
|
||||
#endif /* _LIBC_PRINTF_INTERNAL_H */
|
||||
Reference in New Issue
Block a user