newlib-cygwin/newlib/libc/machine/msp430/tiny-puts.c

21 lines
371 B
C
Raw Normal View History

Implement reduced code size "tiny" printf and puts "tiny" printf is derived from _vfprintf_r in libc/stdio/nano-vfprintf.c. "tiny" puts has been implemented so that it just calls write, without any other processing. Support for buffering, reentrancy and streams has been removed from these functions to achieve reduced code size. This reduced code size implementation of printf and puts can be enabled in an application by passing "--wrap printf" and "--wrap puts" to the GNU linker. This will replace references to "printf" and "puts" in user code with "__wrap_printf" and "__wrap_puts" respectively. If there is no implementation of these __wrap* functions in user code, these "tiny" printf and puts implementations will be linked into the final executable. The wrapping mechanism is supposed to be invisible to the user: - A GCC wrapper option such as "-mtiny-printf" will be added to alias these wrap commands. - If the user is unaware of the "tiny" implementation, and chooses to implement their own __wrap_printf and __wrap_puts, their own implementation will be automatically chosen over the "tiny" printf and puts from the library. Newlib must be configured with --enable-newlib-nano-formatted-io for the "tiny" printf and puts functions to be built into the library. Code size reduction examples: printf("Hello World\n") baseline - msp430-elf-gcc gcc-8_3_0-release text data bss 5638 214 26 "tiny" puts enabled text data bss 714 90 20 printf("Hello %d\n", a) baseline - msp430-elf-gcc gcc-8_3_0-release text data bss 10916 614 28 "tiny" printf enabled text data bss 4632 280 20
2019-04-12 19:08:22 +08:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <newlib.h>
int write (int fd, const char *buf, int len);
int
__wrap_puts (const char * s)
{
int res = write (1, s, strlen (s));
if (res == EOF)
{
write (1, "\n", 1);
return EOF;
}
return write (1, "\n", 1);
}
int puts (const char * s) __attribute__ ((weak, alias ("__wrap_puts")));