From 1bd6a9d4fa1b4801fd646cf37453fb2c5da58b04 Mon Sep 17 00:00:00 2001 From: David Given Date: Mon, 24 Jun 2019 20:52:56 +0200 Subject: [PATCH] Add an itoa() function, following the most common prototype I can find. --- lang/cem/libcc.ansi/core/printf/itoa.c | 13 +++++++++++++ lang/cem/libcc.ansi/headers/stdio.h | 1 + 2 files changed, 14 insertions(+) create mode 100644 lang/cem/libcc.ansi/core/printf/itoa.c diff --git a/lang/cem/libcc.ansi/core/printf/itoa.c b/lang/cem/libcc.ansi/core/printf/itoa.c new file mode 100644 index 000000000..64104f50a --- /dev/null +++ b/lang/cem/libcc.ansi/core/printf/itoa.c @@ -0,0 +1,13 @@ +#include + +void itoa(long value, char* buffer, int radix) +{ + if (value < 0) + { + *buffer++ = '-'; + value = -value; + } + buffer = _i_compute(value, 10, buffer, 0); + *buffer++ = '\0'; +} + diff --git a/lang/cem/libcc.ansi/headers/stdio.h b/lang/cem/libcc.ansi/headers/stdio.h index c6ddb8808..45495d632 100644 --- a/lang/cem/libcc.ansi/headers/stdio.h +++ b/lang/cem/libcc.ansi/headers/stdio.h @@ -75,6 +75,7 @@ extern void perror(const char *_s); /* Internal function used in several places which is approximately itoa(). */ extern char *_i_compute(unsigned long val, int base, char *s, int nrdigits); +extern void itoa(long val, char* buffer, int radix); #if ACKCONF_WANT_EMULATED_FILE #include