diff options
Diffstat (limited to 'os/stdlib')
| -rw-r--r-- | os/stdlib/sdtlib.h | 1 | ||||
| -rw-r--r-- | os/stdlib/stdlib.c | 21 |
2 files changed, 22 insertions, 0 deletions
diff --git a/os/stdlib/sdtlib.h b/os/stdlib/sdtlib.h new file mode 100644 index 0000000..a0b3402 --- /dev/null +++ b/os/stdlib/sdtlib.h @@ -0,0 +1 @@ +char* int_to_str(int i);
\ No newline at end of file diff --git a/os/stdlib/stdlib.c b/os/stdlib/stdlib.c new file mode 100644 index 0000000..465e978 --- /dev/null +++ b/os/stdlib/stdlib.c @@ -0,0 +1,21 @@ +char* int_to_str(int i) +{ + // Room for 4 byte int, -ve sign and null terminator + static char buf[12]; + char *p = buf + 11; // points to null terminator + if (i >= 0) { + do { + *--p = '0' + (i % 10); + i /= 10; + } while (i != 0); + return p; + } + else { + do { + *--p = '0' - (i % 10); + i /= 10; + } while (i != 0); + *--p = '-'; + } + return p; +}
\ No newline at end of file |