A C library that provides atomic file operations with minimal API changes.
zeugl is a lightweight C library that makes file operations atomic by providing drop-in replacements for standard file operations. Instead of directly modifying files (which can lead to corruption), zeugl ensures all file updates are atomic - they either completed fully or don't happen at all.
The library provides drop-in replacements for open() and close() while
keeping standard I/O functions like read() and write() unchanged, allowing
developers to achieve atomicity with just a few line modifications.
- Atomic File Operations: All file modifications are atomic using temporary files and rename operations
- Drop-in Replacement: Simple API with
zopen()andzclose()replacingopen()andclose() - Standard I/O Compatible: Works seamlessly with
read(),write(), and other standard I/O functions - Concurrent Access Protection: Built-in file locking to detect and handle concurrent modifications
- Thread-Safe: Maintains thread safety when compiled with pthread support
- Signal Handling: Automatic cleanup of temporary files on interruption
- When you open a file with
zopen(), zeugl returns a file descriptor to a temporary copy - All modifications happen on the temporary copy
- When you call
zclose(), the temporary file atomically replaces the original - If there is a race between two processes, it's guaranteed that one (and only one) process gets to replace the file
- If the process is interrupted, temporary files are automatically cleaned up
./bootstrap.sh # Bootstrap project
./configure # Configure project
make # Build zeugl
make check # Test zeugl
sudo make install # Install zeuglBy default autotools installs the library to /usr/local/lib. Hence, you may want to add the following line to your ~/.bashrc so that programs can find it:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib"#include <zeugl.h>
// Start atomic file transaction
int fd = zopen("config.txt", flags, mode);
// Use fd with standard I/O functions
write(fd, buffer, size);
// Commit/abort file transaction
zclose(fd, true); // Atomic replacement happens hereThe CLI tool is mainly used for testing, but can be used for updating files atomically on the command line or in shell scripts.
# Atomically update a file
echo "new content" | zeugl -c 644 output.txtContributions are welcome!