From baf30b7b83822b7d6efd0c16761b8e42a1e96101 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 24 Dec 2015 00:11:06 +0100 Subject: Match namespace and directory structure --- src/io.h | 68 ---------------------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 src/io.h (limited to 'src/io.h') diff --git a/src/io.h b/src/io.h deleted file mode 100644 index 69caa5e..0000000 --- a/src/io.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef CHANGE_SRC_IO_H_ -#define CHANGE_SRC_IO_H_ - -#include -#include -#include -#include - -#include - -namespace io { - -class FileDescriptorGuard { - public: - FileDescriptorGuard(const std::string& path) { - this->fd = open(path.c_str(), O_CREAT | O_WRONLY | O_APPEND); - - if ( !this->fd ) { - this->fd = STDERR_FILENO; - } - } - - ~FileDescriptorGuard() { - close(this->fd); - } - - operator int() { - return this->fd; - } - - private: - int fd; - -}; - -std::string get_file_name(int fd) { - char proc_link[20]; - char file_name[256]; - - snprintf(proc_link, sizeof(proc_link), "/proc/self/fd/%d", fd); - const ssize_t name_size = readlink(proc_link, file_name, sizeof(file_name)); - - if ( name_size > 0 ) { - file_name[name_size] = '\0'; - - return std::string(file_name); - } else { - return std::string(); - } -} - -bool is_regular_file(int fd) { - struct stat fd_stat; - fstat(fd, &fd_stat); - - return S_ISREG(fd_stat.st_mode); -} - -bool is_regular_file(const char* path) { - struct stat fd_stat; - lstat(path, &fd_stat); - - return S_ISREG(fd_stat.st_mode); -} - -} - -#endif // CHANGE_SRC_IO_H_ -- cgit v1.2.3