#include #include #include #include #include #include #include #include "Input.h" #include "Exceptions.h" #ifdef HAVE_CONFIG_H #include "config.h" #else #define _(x) x #endif Input::Input(String no) throw (GeneralException) : Handle(no.strlen() ? open(no.to_charp(), O_RDONLY) : dup(0)), n(no) { if (GetHandle() < 0) { throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno)); } size = lseek(GetHandle(), 0, SEEK_END); lseek(GetHandle(), 0, SEEK_SET); struct stat s; fstat(GetHandle(), &s); date_modif = s.st_mtime; } Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) { } bool Input::CanWrite() { return 0; } bool Input::CanRead() { return 1; } bool Input::CanSeek() { struct stat s; fstat(GetHandle(), &s); return S_ISREG(s.st_mode); } String Input::GetName() { return n; } ssize_t Input::GetSize() { return size; } time_t Input::GetModif() { return date_modif; } off_t Input::seek(off_t offset, int whence) throw (GeneralException) { if ((itell = lseek(GetHandle(), offset, whence)) < 0) { throw IOGeneral(String(_("Error seeking file ")) + n + _(": ") + strerror(errno)); } #ifdef PARANOID_SEEK if (itell != lseek(GetHandle(), 0, SEEK_CUR)) { throw IOGeneral(String(_("Error seeking file ")) + n + _(": the position does not match")); } #endif return itell; } Stdin_t::Stdin_t() { } bool Stdin_t::CanSeek() { return 0; } String Stdin_t::GetName() { return "Stdin"; } Stdin_t Stdin;