summaryrefslogtreecommitdiff
path: root/src/boot/libc64/sprintf.c
blob: a2cb2a7e1adea662d34925b0783ae2207b0c587d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "libc64/sprintf.h"

#include "stdint.h"
#include "string.h"

void* proutPrintf(void* dst, const char* fmt, size_t size) {
    return (void*)((uintptr_t)memcpy(dst, fmt, size) + size);
}

int vsprintf(char* dst, const char* fmt, va_list args) {
    int ans = _Printf(proutPrintf, dst, fmt, args);

    if (ans > -1) {
        dst[ans] = 0;
    }
    return ans;
}

int sprintf(char* dst, const char* fmt, ...) {
    int ans;
    va_list args;
    va_start(args, fmt);

    ans = _Printf(proutPrintf, dst, fmt, args);
    if (ans > -1) {
        dst[ans] = 0;
    }

    va_end(args);

    return ans;
}