Debian Codegraph @

vendored-meson/meson/test cases/unit/77 nostdlib/subprojects/mylibc/libc.c

raw
1 /* Do not use this as the basis of your own libc.
2 * The code is probably suboptimal or wonky, as I
3 * had no prior experience with this, but instead
4 * just fiddled with the code until it worked.
5 */
6
7 #include<stdio.h>
8
9 #define STDOUT 1
10 #define SYS_WRITE 4
11
12 int simple_print(const char *msg, const long bufsize) {
13 int count;
14 long total_written = 0;
15 while(total_written < bufsize) {
16 asm(
17 "int $0x80\n\t"
18 : "=a"(count)
19 : "0"(SYS_WRITE), "b"(STDOUT), "c"(msg+total_written), "d"(bufsize-total_written)
20 :);
21 if(count == 0) {
22 return 1;
23 }
24 total_written += count;
25 }
26 return 0;
27 }
28
29 int simple_strlen(const char *str) {
30 int len = 0;
31 while(str[len] != '\0') {
32 len++;
33 }
34 return len;
35 }