Module

std::libc::string

LibC String

Null-terminated C string operations from string.h, exposed as LibC::String.

Functions

Function Description
strlen Length of null-terminated string
strcmp Compare two strings (returns 0 if equal)
strncmp Compare up to n bytes
strcpy Copy string including null terminator
strncpy Copy up to n bytes, null-padding if shorter
strcat Append string to end of destination
strncat Append up to n bytes
strchr Find first occurrence of byte in string
strrchr Find last occurrence of byte in string
strstr Find first occurrence of substring
strdup Duplicate string (caller must free)
strerror Human-readable string for an errno value

All functions operate on raw CType::CStr / CType::CConstStr pointers. The caller is responsible for buffer sizes and null termination. Do not use these APIs for Ignis String byte-length semantics; they are raw C-string helpers and may stop at the first interior NUL byte.

Example

import LibC, CType from "std::libc";

function main(): i32 {
  let msg: CType::CConstStr = "hello, world";
  let len: CType::SizeT = LibC::String::strlen(msg);

  // Duplicate and compare
  let copy: CType::CStr = LibC::String::strdup(msg);
  let eq: CType::CInt = LibC::String::strcmp(msg, copy);
  LibC::Allocator::free(copy as CType::CVoidPtr);

  // Find substring
  let pos: CType::CStr = LibC::String::strstr(msg, "world");

  return 0;
}
namespace __string_ops

Functions

function strcat(dest: *mut u8, src: *u8): *mut u8

C strcat; appends src to dest.

function strchr(s: *u8, c: i32): *mut u8

C strchr; returns the first matching byte in s.

function strcmp(s1: *u8, s2: *u8): i32

C strcmp; compares two NUL-terminated strings.

function strcpy(dest: *mut u8, src: *u8): *mut u8

C strcpy; copies a NUL-terminated string into dest.

function strdup(s: *u8): *mut u8

C strdup; allocates a duplicate string with the C allocator.

function strerror(errnum: i32): *mut u8

C strerror; returns a host-owned error message for errnum.

function strlen(s: *u8): u64

C strlen; returns bytes before the first NUL.

function strncat(dest: *mut u8, src: *u8, n: u64): *mut u8

C strncat; appends at most n bytes from src to dest.

function strncmp(s1: *u8, s2: *u8, n: u64): i32

C strncmp; compares at most n bytes.

function strncpy(dest: *mut u8, src: *u8, n: u64): *mut u8

C strncpy; copies at most n bytes into dest.

function strrchr(s: *u8, c: i32): *mut u8

C strrchr; returns the last matching byte in s.

function strstr(haystack: *u8, needle: *u8): *mut u8

C strstr; returns the first occurrence of needle.

namespace String

String operations (string.h)

Functions

function strcat(dest: *mut u8, src: *u8): *mut u8

Appends src to the end of dest.

function strchr(s: *u8, c: i32): *mut u8

Finds the first occurrence of byte c in string s.

function strcmp(s1: *u8, s2: *u8): i32

Compares two null-terminated strings. Returns 0 if equal.

function strcpy(dest: *mut u8, src: *u8): *mut u8

Copies src to dest including the null terminator.

function strdup(s: *u8): *mut u8

Duplicates a string into newly allocated memory. Caller must free.

function strerror(errnum: i32): *mut u8

Returns a human-readable string for the given error number.

function strlen(s: *u8): u64

Returns the length of the null-terminated string s.

function strncat(dest: *mut u8, src: *u8, n: u64): *mut u8

Appends at most n bytes of src to dest.

function strncmp(s1: *u8, s2: *u8, n: u64): i32

Compares at most n bytes of two strings. Returns 0 if equal.

function strncpy(dest: *mut u8, src: *u8, n: u64): *mut u8

Copies at most n bytes from src to dest, null-padding if src is shorter.

function strrchr(s: *u8, c: i32): *mut u8

Finds the last occurrence of byte c in string s.

function strstr(haystack: *u8, needle: *u8): *mut u8

Finds the first occurrence of needle in haystack.