Skip to main content

ax_libc/
lib.rs

1//! [ArceOS] user program library for C apps.
2//!
3//! ## Cargo Features
4//!
5//! - CPU
6//!     - `smp`: Enable SMP (symmetric multiprocessing) support.
7//!     - `fp-simd`: Enable floating point and SIMD support.
8//! - Interrupts:
9//!     - Interrupt handling is always available.
10//! - Memory
11//!     - `alloc`: Enable dynamic memory allocation.
12//!     - `tls`: Enable thread-local storage.
13//! - Task management
14//!     - Multi-threading and timer-driven scheduling are always available.
15//! - Upperlayer stacks
16//!     - `fs`: Enable file system support.
17//!     - `net`: Enable networking support.
18//! - Lib C functions
19//!     - `fd`: Enable file descriptor table.
20//!     - `pipe`: Enable pipe support.
21//!     - `select`: Enable synchronous I/O multiplexing ([select]) support.
22//!     - `epoll`: Enable event polling ([epoll]) support.
23//!
24//! [ArceOS]: https://github.com/arceos-org/arceos
25//! [select]: https://man7.org/linux/man-pages/man2/select.2.html
26//! [epoll]: https://man7.org/linux/man-pages/man7/epoll.7.html
27
28#![cfg_attr(all(not(test), not(doc)), no_std)]
29#![cfg_attr(feature = "tls", feature(thread_local))]
30#![allow(clippy::missing_safety_doc)]
31
32#[cfg(feature = "alloc")]
33extern crate alloc;
34extern crate ax_driver as _;
35
36use ax_posix_api::ctypes;
37
38#[macro_use]
39mod utils;
40
41#[cfg(feature = "fd")]
42mod fd_ops;
43#[cfg(feature = "fs")]
44mod fs;
45#[cfg(any(feature = "select", feature = "epoll"))]
46mod io_mpx;
47#[cfg(feature = "alloc")]
48mod malloc;
49#[cfg(feature = "net")]
50mod net;
51#[cfg(feature = "pipe")]
52mod pipe;
53mod pthread;
54#[cfg(feature = "alloc")]
55mod strftime;
56#[cfg(feature = "fp-simd")]
57mod strtod;
58
59mod errno;
60mod io;
61mod mktime;
62mod rand;
63mod resource;
64mod setjmp;
65mod sys;
66mod time;
67mod unistd;
68
69#[cfg(feature = "fd")]
70pub use self::fd_ops::{ax_fcntl, close, dup, dup2, dup3};
71#[cfg(feature = "fs")]
72pub use self::fs::{ax_open, fstat, getcwd, lseek, lstat, rename, stat};
73#[cfg(not(test))]
74pub use self::io::write;
75#[cfg(feature = "select")]
76pub use self::io_mpx::select;
77#[cfg(feature = "epoll")]
78pub use self::io_mpx::{epoll_create, epoll_create1, epoll_ctl, epoll_wait};
79#[cfg(feature = "alloc")]
80pub use self::malloc::{free, malloc};
81#[cfg(feature = "net")]
82pub use self::net::{
83    accept, bind, connect, freeaddrinfo, getaddrinfo, getpeername, getsockname, listen, recv,
84    recvfrom, send, sendto, shutdown, socket,
85};
86#[cfg(feature = "pipe")]
87pub use self::pipe::pipe;
88#[cfg(feature = "alloc")]
89pub use self::strftime::strftime;
90#[cfg(feature = "fp-simd")]
91pub use self::strtod::{strtod, strtof};
92pub use self::{
93    errno::strerror,
94    io::{read, writev},
95    mktime::mktime,
96    pthread::{
97        pthread_create, pthread_detach, pthread_exit, pthread_join, pthread_mutex_init,
98        pthread_mutex_lock, pthread_mutex_unlock, pthread_self,
99    },
100    rand::{rand, random, srand},
101    resource::{getrlimit, setrlimit},
102    setjmp::{longjmp, setjmp},
103    sys::sysconf,
104    time::{clock_gettime, nanosleep},
105    unistd::{abort, exit, getpid},
106};