Skip to content

maxtyson123/LibC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Headers Functions Build Lines of Code wakatime


Logo

LibC

My own implementaion of the C standard library to be used in MaxOS (compatible with other OSes)
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Add your own platform
  5. Contributing
  6. License
  7. Acknowledgments

About The Project

MaxOS

LibC is my implementation of the C standard library, compliant with The Open Group Standard Base Specifications's POSIX.1-2024 (IEEE Std 1003.1) specification. This LibC is designed to be easily portable to other hobby kernels requiring a single header consisting of a only couple definitions and 16 'glue' functions.

I created this (rather than using a more efficient, pre-existing one ) as a learning experience. It has been fun diving into how a OS works and I thought it would also be fun to dive into how the OS exposes an API to userspace via the standard c library. Additionally, I didn't like the organisation of some of the other LibC implementations out there (personal preference) which was added incentive.

Currently, LibC is not finished and thus doesnt support any platforms, however, in the future I plan to implement support for MaxOS, MacOS and Linux. Maybe even a port for windows in the future.

This repo houses the source code for the standard library and some supporting scripts to build documentation. The repository also contains the latest build, which can be downloaded from the workflow artifacts.

(back to top)

Getting Started

This is how to build the LibC library from source and install it into your system or project. (Alternatively, you can download the latest built library from the workflow artifacts)

Currently, LibC cant build yet, will be updated later.

Prerequisites

To build LibC needs a valid compiler and cmake version 3.31 or higher.

You will also need to pick a target from the following:

Target Description
example Minmal stub implementation, will compile but most will error
MaxOS Native LibC for MaxOS kernel and userspace

Build

  1. Clone the repo

    git clone https://github.com/maxtyson123/LibC.git
    cd LibC
  2. Choose a target and sysroot (can be anypath, doesnt have to follow format below)

    SYSROOT="$HOME/{target}/sysroot"
    mkdir -p $SYSROOT
  3. Configure the build

    mkdir build
    cd build
    cmake -DCMAKE_BUILD_TYPE=Release -DLIBC_TARGET=example -DCMAKE_INSTALL_PREFIX=$SYSROOT ..
  4. Build and install

    cmake --build .
    cmake --install .

(back to top)

Usage

  • Option A: To use in a CMAKE project add the following lines to your CMAKELists.txt:
     FIND_PACKAGE(LibC REQUIRED)
     TARGET_LINK_LIBRARIES(proj PRIVATE LibC::c)
  • Option B: To use in a cross compiler:
     x86_64-elf-gcc --sysroot=$SYSROOT -ffreestanding -nostdlib main.c -lc -o main.elf
    Note: Ensure -nostdlib and -ffreestanding are passed to avoid linking against the host libc.

Add your own platform

Included is the example platform target which is a minimal stub implementation of a platform the supports none of the platform specific features. Whilst the example platform should compile, it is not recommended to use as most of the standard functions will error.

When adding your own platform, it is recommended to copy the example and replace each part with the specific values and implementations that your platform offers. Additionally, you will have to setup the build options for your target in the CMakeLists.txt file.

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the BSD 3-Clause License. See LICENSE for more information.

(back to top)

Acknowledgments

(back to top)

About

My own implementaion of the C standard library to be used in MaxOS (compatible with other OSes)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published