Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CRISTOP-bot/cris-os-v2/llms.txt
Use this file to discover all available pages before exploring further.
kstring.h provides the kernel’s freestanding string and memory utilities. Because CrisOS v2 is compiled with -nostdlib, there is no <string.h> or <stdio.h>. All string and memory operations kernel-wide use these functions instead, ensuring no dependency on any C runtime. Include kstring.h in any kernel translation unit that needs string manipulation, comparison, or integer-to-string conversion.
String Length
kstrlen
s before the terminating NUL character. Equivalent to libc strlen.
NUL-terminated string to measure.
s in bytes, not including the NUL terminator.
String Comparison
kstrcmp
strcmp.
First NUL-terminated string.
Second NUL-terminated string.
a < b, 0 if a == b, or a positive integer if a > b.
kstrncmp
n bytes of two strings. Stops at the first differing byte or at a NUL terminator in either string. Equivalent to libc strncmp.
First string.
Second string.
Maximum number of bytes to compare.
a < b, 0 if equal within n bytes, or a positive integer if a > b.
String Copy and Concatenation
kstrcpy
src into dest, writing at most maxlen - 1 characters and always NUL-terminating the result. Similar to BSD strlcpy rather than strcpy — the destination is always NUL-terminated regardless of whether src was truncated.
Destination buffer.
NUL-terminated source string.
Total size of the destination buffer in bytes, including space for the NUL terminator. If
maxlen is 0, nothing is written.dest.
Unlike
strcpy, kstrcpy will never write beyond maxlen bytes into dest. The result is always NUL-terminated when maxlen > 0.kstrcat
src to the end of dest. maxlen is the total size of the destination buffer (not the number of bytes to append). The result is always NUL-terminated when maxlen > 0 and dest already contains a NUL within the buffer.
Destination buffer containing a NUL-terminated string to append to.
NUL-terminated string to append.
Total capacity of the destination buffer in bytes. Appending stops before the buffer would be exceeded.
dest.
maxlen is the full buffer size, not the remaining free space. This differs from libc strncat, where the third argument is the maximum number of bytes to append.String Search
kstrstr
needle within haystack. Equivalent to libc strstr.
NUL-terminated string to search within.
NUL-terminated substring to find. If empty,
haystack is returned immediately.needle in haystack; NULL if not found.
kstrchr
c in s. Equivalent to libc strchr. Does not search past the NUL terminator.
NUL-terminated string to search.
Character to search for.
c in s; NULL if not found.
Memory Operations
kmemset
n bytes of s with the byte value (unsigned char)c. Equivalent to libc memset.
Pointer to the memory region to fill.
Byte value to fill with (only the low 8 bits are used).
Number of bytes to fill.
s.
kmemcpy
n bytes from src to dest. The regions must not overlap. Equivalent to libc memcpy.
Destination memory region.
Source memory region. Must not overlap with
dest.Number of bytes to copy.
dest.
kmemcmp
n bytes of two memory regions using unsigned byte values. Equivalent to libc memcmp.
First memory region.
Second memory region.
Number of bytes to compare.
a < b, 0 if both regions are identical, or a positive integer if a > b.
Integer Conversion
kitoa
value to its decimal string representation and writes it into buf. Negative values are prefixed with '-'. The result is always NUL-terminated when maxlen > 0. There is no direct libc equivalent; the closest standard function is snprintf(buf, maxlen, "%ld", value).
The signed integer to convert.
Output buffer to write the decimal string into.
Total capacity of
buf in bytes. The output is silently truncated if maxlen is too small. If maxlen is 0, nothing is written.void).
Inline Helpers
These functions are defined asstatic inline in kstring.h and generate no separate object code.
kskip_spaces
s past any leading whitespace characters: space (' '), horizontal tab ('\t'), carriage return ('\r'), and newline ('\n').
Pointer into a string, positioned at or before the first non-whitespace character.
s that is not a whitespace character; or a pointer to the NUL terminator if s is entirely whitespace.
kstreq
kstrcmp, which returns 0 for equal strings, kstreq returns 1 for equal strings and 0 for unequal — matching a boolean convention and avoiding the inverted-zero check.
First NUL-terminated string.
Second NUL-terminated string.
1 if a and b are identical; 0 otherwise.
kstreq returns 1 for equality, which is the opposite sign convention from kstrcmp. Use kstreq when you want a boolean result and kstrcmp when you need ordering information.