|
libcppwrap
A collection of C++ wrappers for native APIs
|
libcppwrap is a collection of low-level C++ wrappers around native C APIs such as POSIX functions and BSD sockets. It provides the following features on top of the native functions, while duplicating the function signatures as closely as possible:
std::system_error exceptions instead of returning error codes.w::handle type.fcntl() and ioctl(), which can take input and/or output parameters of arbitrary type, are implemented as type-safe templates.sockaddr_in are provided with useful constructors for initialization. Use of the derived structures is always optional.The philosophy of the library is to stay as faithful as possible to the native API, while ensuring type- and exception-safety and resource management as robustly as possible. Some helper functions which deviate from the native APIs or add missing functionality are implemented in a separate, optional namespace, which can be disabled.
The library is currently very POSIX-centric, being developed for and tested on Linux. It could and may eventually be extended to include native APIs for other platforms like Windows.
libcppwrap exposes two namespaces, w and wx. The w namespace contains the core wrappers, which follow the native APIs as closely as possible. The wx namespace contains useful extensions which deviate from the native API but provide low-level functionality that would not necessarily justify a separate library.
#include <w/posix.hpp>
auto fd = w::open("file.txt", "at");
w::write(fd, "hello", 5);
// fd is automatically closed when it goes out of scope
libcppwrap is published under the MIT License. See the file LICENSE.txt for the full license text.