https://github.com/stort0/cfs
Single header cross-platform filesystem API in C89.
https://github.com/stort0/cfs
32-bit 64-bit c c89 c90 cross-platform filesystem filesystem-library linux single-header single-header-library windows
Last synced: 11 days ago
JSON representation
Single header cross-platform filesystem API in C89.
- Host: GitHub
- URL: https://github.com/stort0/cfs
- Owner: stort0
- Created: 2025-02-16T14:33:50.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-12-28T10:11:17.000Z (7 months ago)
- Last Synced: 2025-12-30T20:09:50.477Z (7 months ago)
- Topics: 32-bit, 64-bit, c, c89, c90, cross-platform, filesystem, filesystem-library, linux, single-header, single-header-library, windows
- Language: C
- Homepage:
- Size: 620 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
> ⚠️ Warning
> The library is currently being tested.
# CFS: cross-platform filesystem API in C89
A single header implementation of `std::filesystem`/`Boost.Filesystem` in `C89`.
> ⚠️ Warning
> The library will not compile in a C++ environment (yet).
> Define **CFS_IMPLEMENTATION** in a **C** file instead.
### Usage:
```c++
// This should be done in a source file, not a header file.
// For Linux:
// #define _GNU_SOURCE
// Already defined by most compilers, required for some functions.
// This should be defined as a compiler definition, not using a #define.
// If defined in a .c file, it should be above all #includes.
// For Windows:
// Be sure to use a toolchain that automatically defines _WIN32_WINNT
// to enable symlinks.
#define CFS_IMPLEMENTATION
#include
```
### OS requirements
| Windows | Linux |
|:------------------|:------|
| Windows **95+**\* | Any |
\* Only compatibility with **Windows 2000+** are tested in a VM. Older Windows
versions are checked by modifying the `_WIN32_WINNT` value.
Some specific fixes are implemented for `FreeBSD` and `Darwin` but compatibility
won't be tested.
## Differences with std::filesystem
`std::filesystem` implementation across compilers is *extremely* inconsistent. This
library adopts the most **common** or **logical** way across various implementations,
or a **custom** one.
- On `Windows`, paths above `MAX_PATH` *(260 chars)* length are supported.
- Empty paths `""` are **not** transformed in `"."` and `NULL` paths are treated as
an error in `Debug` (**fs_cfs_error_invalid_argument**) or **undefined behavior**
in `Release` mode.
- `fs_file_time_type` is based on the **UNIX** epoch on **all** OSs.
- `fs_hard_link_count` always does **not** include the file itself as a link for
consistency across operating systems.