Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/native/kernel/core/libc_min.c # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / native / kernel / core / libc_min.c` 73 lines ยท 1943 bytes Raw Blame History 1 /* SPDX-License-Identifier: Apache-2.0 2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* libc_min.c -- the memory and string routines a freestanding C image still 18 * needs (the compiler may emit calls to memcpy/memset/memmove/memcmp, and the 19 * native/ modules linked as stages use them). Plain byte loops: safe on 20 * Normal Non-cacheable memory; -fno-tree-loop-distribute-patterns keeps the 21 * compiler from turning them back into calls to themselves. Kernel only. */ 22 #include 23 #include 24 25 void *memcpy(void *dst, const void *src, size_t n) 26 { 27 uint8_t *d = dst; 28 const uint8_t *s = src; 29 while (n--) 30 *d++ = *s++; 31 return dst; 32 } 33 34 void *memmove(void *dst, const void *src, size_t n) 35 { 36 uint8_t *d = dst; 37 const uint8_t *s = src; 38 if (d < s) { 39 while (n--) 40 *d++ = *s++; 41 } else if (d > s) { 42 d += n; 43 s += n; 44 while (n--) 45 *--d = *--s; 46 } 47 return dst; 48 } 49 50 void *memset(void *dst, int c, size_t n) 51 { 52 uint8_t *d = dst; 53 while (n--) 54 *d++ = (uint8_t)c; 55 return dst; 56 } 57 58 int memcmp(const void *a, const void *b, size_t n) 59 { 60 const uint8_t *x = a, *y = b; 61 for (; n; n--, x++, y++) 62 if (*x != *y) 63 return *x < *y ? -1 : 1; 64 return 0; 65 } 66 67 size_t strlen(const char *s) 68 { 69 size_t n = 0; 70 while (s[n]) 71 n++; 72 return n; 73 }