An open API service indexing awesome lists of open source software.

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.

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.