aboutsummaryrefslogtreecommitdiffstats
path: root/src/stdlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdlib.c')
-rw-r--r--src/stdlib.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/src/stdlib.c b/src/stdlib.c
index fa2806b..1832033 100644
--- a/src/stdlib.c
+++ b/src/stdlib.c
@@ -1,4 +1,10 @@
+#include <stdarg.h>
#include <stdint.h>
+#include <string.h>
+
+#include <heap.h>
+
+extern char *itoa(int, char *, int);
void _exit(int code)
{
@@ -6,28 +12,33 @@ void _exit(int code)
for (;;);
}
-int _getpid(int pid)
+int ksnprintf(char *buf, unsigned int count, const char *format, ...)
{
- (void)pid;
- return 0;
-}
+ (void)count;
-void _kill(int pid)
-{
- (void)pid;
-}
+ va_list args;
+ va_start(args, format);
-void _sbrk(void)
-{
+ unsigned int i = 0, o = 0;
+ while (o < count && format[i] != '\0') {
+ if (format[i] == '%') {
+ if (format[i + 1] == 'd') {
+ char *s = itoa(va_arg(args, int), malloc(16), 10);
+ strncpy(buf + o, s, count - o);
+ o += strlen(s);
+ free(s);
+ } else if (format[i + 1] == 'f') {
+ strncpy(buf + o, "float", count - o);
+ o += 5;
+ }
+ i++;
+ } else {
+ buf[o++] = format[i];
+ }
-}
+ i++;
+ }
-char *itoa(int n, int base)
-{
- static char buf[16];
- char *p = buf + 15;
- *p = '\0';
- do *--p = "0123456789ABCDEF"[n % base];
- while (n /= base);
- return p;
+ return o;
}
+