74 lines
2.1 KiB
Markdown
74 lines
2.1 KiB
Markdown
# CgeFile - File Access Library for C
|
|
|
|
A lightweight, dependency-free C library providing a consistent interface for
|
|
file operations across different operating systems. The library abstracts
|
|
platform-specific details and offers a unified API for reading, writing, and
|
|
manipulating files
|
|
|
|
## Features
|
|
|
|
- Cross-platform compatibility (Linux, macOS, Windows, POSIX systems)
|
|
- Multiple file modes (read, write, read/write, append, truncate, create,
|
|
existence checking)
|
|
- Flexible seeking (relative, absolute, end-based positioning)
|
|
- Comprehensive error handling with detailed error codes
|
|
- File metadata retrieval (size, current position, flags)
|
|
- Peek functionality (read data without advancing the file pointer)
|
|
- Buffering and flushing (control data persistence)
|
|
- EOF detection and error clearing
|
|
|
|
## Usage Example
|
|
|
|
```c
|
|
#include "CgeFile.h"
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
int main(void) {
|
|
int result;
|
|
CgeFile *file = CgeFileNew("example.txt", CGE_FILE_READWRITE | CGE_FILE_CREATE, &result);
|
|
if (!file) {
|
|
fprintf(stderr, "Failed to open file: error code %d\n", result);
|
|
return 1;
|
|
}
|
|
|
|
const char *data = "Hello, CgeFile!";
|
|
size_t written;
|
|
if (!CgeFileWrite(file, data, strlen(data), &written)) {
|
|
fprintf(stderr, "Write failed\n");
|
|
CgeFileFree(file);
|
|
return 1;
|
|
}
|
|
|
|
char buffer[100];
|
|
size_t actual;
|
|
if (CgeFileSeek(file, 0, CGE_FILE_SET) &&
|
|
CgeFileRead(file, buffer, sizeof(buffer) - 1, &actual)) {
|
|
buffer[actual] = '\0';
|
|
printf("Read: %s\n", buffer);
|
|
}
|
|
|
|
CgeFileFree(file);
|
|
return 0;
|
|
}
|
|
```
|
|
|
|
## Build Systems
|
|
|
|
- **CMake**: supports Linux, macOS, Windows (MSVC, MinGW)
|
|
- **Makefile.posix**: for GCC/Clang on POSIX systems
|
|
- **Makefile.mingw**: for MinGW on Windows
|
|
- **Makefile.win32**: for MSVC with NMake
|
|
|
|
Builds a static library. No shared library or external dependencies
|
|
|
|
## Portability
|
|
|
|
- **Standard compliance**: written in C89 + stdint.h
|
|
- **No dynamic memory allocation**: all memory management is explicit
|
|
- **No external dependencies**: relies only on standard C libraries
|
|
|
|
## License
|
|
|
|
0BSD - a permissive license with no attribution required.
|