12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include "OS.h"
-
- #include <stdexcept>
- #include <unistd.h>
- #include <dlfcn.h>
-
- #include "log.h"
-
- namespace Swan {
- namespace OS {
-
- bool isTTY(FILE *f) {
- int fd = fileno(f);
- return isatty(fd);
- }
-
- Dynlib::Dynlib(const std::string &path) {
- handle_ = dlopen((path + ".so").c_str(), RTLD_LAZY);
- if (!handle_)
- throw std::runtime_error(dlerror());
- }
-
- Dynlib::Dynlib(Dynlib &&dl) noexcept: handle_(dl.handle_) {
- dl.handle_ = nullptr;
- }
-
- Dynlib::~Dynlib() {
- if (handle_)
- dlclose(handle_);
- }
-
- Dynlib &Dynlib::operator=(Dynlib &&dl) noexcept {
- handle_ = dl.handle_;
- dl.handle_ = nullptr;
- return *this;
- }
-
- void *Dynlib::getVoid(const std::string &name) {
- return dlsym(handle_, name.c_str());
- }
-
- }
- }
|