-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplatform.cpp
41 lines (30 loc) · 1022 Bytes
/
platform.cpp
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
33
34
35
36
37
38
39
40
41
// Copyright (c) 2016-2024 Knuth Project developers.
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <kth/capi/platform.h>
#include <cstdlib>
#include <kth/capi/helpers.hpp>
// ---------------------------------------------------------------------------
extern "C" {
void kth_platform_free(void* ptr) {
free(ptr);
}
char* kth_platform_allocate_string(kth_size_t n) {
return kth::mnew<char>(n);
}
void kth_platform_allocate_string_at(char** ptr, kth_size_t n) {
*ptr = kth::mnew<char>(n);
}
char** kth_platform_allocate_array_of_strings(kth_size_t n) {
return kth::mnew<char*>(n);
}
void kth_platform_print_string(char* str) {
printf("%s\n", str);
}
char* kth_platform_allocate_and_copy_string_at(char** ptr, kth_size_t offset, char const* str) {
auto n = strlen(str);
ptr[offset] = kth::mnew<char>(n);
std::copy_n(str, n + 1, ptr[offset]);
return ptr[offset];
}
} //extern "C"