Select Git revision
rtt_rtic_i2c.rs
tiny_printf.c 8.49 KiB
/**
*****************************************************************************
**
** File : tiny_printf.c
**
** Abstract : Atollic TrueSTUDIO Minimal iprintf/siprintf/fiprintf
** and puts/fputs.
** Provides aliased declarations for printf/sprintf/fprintf
** pointing to *iprintf variants.
**
** The argument contains a format string that may include
** conversion specifications. Each conversion specification
** is introduced by the character %, and ends with a
** conversion specifier.
**
** The following conversion specifiers are supported
** cdisuxX%
**
** Usage:
** c character
** d,i signed integer (-sign added, + sign not supported)
** s character string
** u unsigned integer as decimal
** x,X unsigned integer as hexadecimal (uppercase letter)
** % % is written (conversion specification is '%%')
**
** Note:
** Character padding is not supported
**
** Environment : Atollic TrueSTUDIO
**
** Distribution: The file is distributed "as is", without any warranty
** of any kind.
**
** (c)Copyright Atollic AB.
** You may use this file as-is or modify it according to the needs of your
** project. This file may only be built (assembled or compiled and linked)
** using the Atollic TrueSTUDIO(R) product. The use of this file together
** with other tools than Atollic TrueSTUDIO(R) is not permitted.
**
*****************************************************************************
*/
/* Includes */
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
/* Create aliases for *printf to integer variants *iprintf */
__attribute__ ((alias("iprintf"))) int printf(const char *fmt, ...);
__attribute__ ((alias("fiprintf"))) int fprintf(FILE* fp, const char *fmt, ...);
__attribute__ ((alias("siprintf"))) int sprintf(char* str, const char *fmt, ...);
/* External function prototypes (defined in syscalls.c) */
extern int _write(int fd, char *str, int len);
/* Private function prototypes */
void ts_itoa(char **buf, unsigned int d, int base);
int ts_formatstring(char *buf, const char *fmt, va_list va);
int ts_formatlength(const char *fmt, va_list va);
/* Private functions */
/**
**---------------------------------------------------------------------------
** Abstract: Convert integer to ascii
** Returns: void
**---------------------------------------------------------------------------
*/
void ts_itoa(char **buf, unsigned int d, int base)