Skip to main content

Overview

relibc is a C standard library (POSIX-compatible libc) implementation written in Rust for Redox OS. It provides the standard C library interface while leveraging Rust’s safety guarantees under the hood.

relibc Repository

View the relibc source code on GitLab

Key Features

POSIX Compliance

Implements standard C library functions and POSIX APIs

Rust Safety

Core implementation in Rust for memory safety

Linux Compatibility

Provides compatibility with Linux applications

BSD Support

Compatible with many BSD programs

Purpose

relibc serves as the bridge between C/C++ applications and Redox OS:
  • Application compatibility: Allows running existing C/C++ software on Redox
  • POSIX interface: Provides familiar POSIX APIs for developers
  • Safe implementation: Uses Rust internally for critical operations
  • Cross-platform: Works on both Redox and Linux (for testing)

Architecture

relibc is structured as a hybrid implementation:
// External C API
extern "C" fn open(path: *const c_char, flags: c_int) -> c_int {
    // Rust implementation calling Redox schemes
    // Provides safety while maintaining C compatibility
}

Building with relibc

Programs link against relibc automatically in the Redox build system:
[packages]
relibc = {}      # C standard library
libgcc = {}      # GCC runtime
libstdcxx = {}   # C++ standard library

Standard Library Support

relibc implements most standard C library functions:
// Standard I/O functions
FILE *fopen(const char *path, const char *mode);
int fprintf(FILE *stream, const char *format, ...);
int printf(const char *format, ...);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);

Device File Mapping

relibc translates standard device files to Redox schemes:
// Standard device files mapped through relibc
open("/dev/null", O_RDWR);    // Maps to null: scheme
open("/dev/random", O_RDONLY); // Maps to rand: scheme
open("/dev/tty", O_RDWR);     // Maps to libc:tty
open("/dev/stdin", O_RDONLY);  // Maps to libc:stdin

Porting Applications

Many applications can be ported to Redox with minimal changes thanks to relibc:
1

Build with Redox toolchain

Use the Redox cross-compilation toolchain that links against relibc
2

Handle platform differences

Some system-specific features may need conditional compilation
3

Test compatibility

Test the application on Redox to identify any missing APIs
Redox provides source code compatibility with many Rust, Linux, and BSD programs through relibc.

Configuration

relibc is part of the base system:
[packages]
relibc = {}

[dependencies]
libc = "0.2"  # Rust programs can use the libc crate

Cargo Integration

The Redox build system includes relibc in its dependencies:
[dependencies]
libc = "0.2"
termion = "4"  # Terminal library that uses relibc

Resources

relibc Repository

Source code and development

Redox Book

Documentation on porting applications

POSIX Compliance

Supported POSIX features

Developer FAQ

Common questions about relibc

Maintainer

Jeremy Soller (@jackpot51)

Primary maintainer of relibc

Build docs developers (and LLMs) love