aboutsummaryrefslogtreecommitdiff
path: root/examples/kaas/kaas.c
blob: 446947471a70fb54f0299ca10e75f5a2d045b9b2 (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
33
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>

__attribute__((constructor))
void constr() {
	printf("kaas: constructor!\n");
}

__attribute__((destructor))
void destr() {
	printf("kaas: destructor!\n");
}

int worker_init(int version) {
	printf("kaas: initialised with version %d\n", version);
	return 0;
}

int worker_run_job(size_t size, void *input_, size_t *outsize, void **outputp) {
	printf("kaas: running job (size = %zu)\n", size);
	const char *input = input_;
	char *output = malloc(size);
	for (size_t i = 0; i < size; i++) output[i] = toupper(input[i]);
	*outsize = size;
	*outputp = output;
	return 0;
}

void worker_free_outdata(size_t size, void *data) {
	(void)size;
	free(data);
}