From d798bbb1067dac005e362f5d106f929d488ea258 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 6 Feb 2016 12:19:01 -0500 Subject: [PATCH] FS: Removed obsolete code --- src/FS.cpp | 133 +++++++---------------------------------------------- src/FS.h | 12 +---- 2 files changed, 17 insertions(+), 128 deletions(-) diff --git a/src/FS.cpp b/src/FS.cpp index 6d26258..697f466 100644 --- a/src/FS.cpp +++ b/src/FS.cpp @@ -37,9 +37,7 @@ #include #include #include -#include #include -#include #include #if defined SOLARIS || defined NETBSD || defined FREEBSD @@ -55,13 +53,6 @@ #define GLOB_BRACE 0 #endif -//////////////////////////////////////////////////////////////////////////////// -std::ostream& operator<< (std::ostream& out, const Path& path) -{ - out << path._data; - return out; -} - //////////////////////////////////////////////////////////////////////////////// Path::Path () { @@ -84,11 +75,6 @@ Path::Path (const std::string& in) _data = expand (in); } -//////////////////////////////////////////////////////////////////////////////// -Path::~Path () -{ -} - //////////////////////////////////////////////////////////////////////////////// Path& Path::operator= (const Path& other) { @@ -406,12 +392,6 @@ bool File::open () return false; } -//////////////////////////////////////////////////////////////////////////////// -bool File::openAndLock () -{ - return open () && lock (); -} - //////////////////////////////////////////////////////////////////////////////// void File::close () { @@ -434,9 +414,7 @@ bool File::lock () if (_fh && _h != -1) { // l_type l_whence l_start l_len l_pid - struct flock fl {}; - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; + struct flock fl = {F_WRLCK, SEEK_SET, 0, 0, 0 }; fl.l_pid = getpid (); if (fcntl (_h, F_SETLKW, &fl) == 0) _locked = true; @@ -451,9 +429,7 @@ void File::unlock () if (_locked) { // l_type l_whence l_start l_len l_pid - struct flock fl {}; - fl.l_type = F_UNLCK; - fl.l_whence = SEEK_SET; + struct flock fl = {F_UNLCK, SEEK_SET, 0, 0, 0 }; fl.l_pid = getpid (); fcntl (_h, F_SETLK, &fl); @@ -498,31 +474,6 @@ void File::read (std::vector & contents) } } -//////////////////////////////////////////////////////////////////////////////// -// Opens if necessary. -void File::write (const std::string& line) -{ - if (!_fh) - open (); - - if (_fh) - fputs (line.c_str (), _fh); -} - -//////////////////////////////////////////////////////////////////////////////// -// Opens if necessary. -void File::write (const std::vector & lines) -{ - if (!_fh) - open (); - - if (_fh) - { - for (auto& line : lines) - fputs (line.c_str (), _fh); - } -} - //////////////////////////////////////////////////////////////////////////////// // Opens if necessary. void File::append (const std::string& line) @@ -548,7 +499,19 @@ void File::append (const std::vector & lines) { fseek (_fh, 0, SEEK_END); for (auto& line : lines) - fputs ((line + "\n").c_str (), _fh); + fputs (line.c_str (), _fh); + } +} + +//////////////////////////////////////////////////////////////////////////////// +void File::write_raw (const std::string& line) +{ + if (!_fh) + open (); + + if (_fh) + { + fputs (line.c_str (), _fh); } } @@ -559,7 +522,7 @@ void File::truncate () open (); if (_fh) - ftruncate (_h, 0); + (void) ftruncate (_h, 0); } //////////////////////////////////////////////////////////////////////////////// @@ -646,25 +609,6 @@ bool File::create (const std::string& name, int mode /* = 0640 */) return false; } -//////////////////////////////////////////////////////////////////////////////// -std::string File::read (const std::string& name) -{ - std::string contents = ""; - - std::ifstream in (name.c_str ()); - if (in.good ()) - { - std::string line; - line.reserve (1024); - while (getline (in, line)) - contents += line + "\n"; - - in.close (); - } - - return contents; -} - //////////////////////////////////////////////////////////////////////////////// bool File::read (const std::string& name, std::string& contents) { @@ -745,46 +689,6 @@ bool File::write ( return false; } -//////////////////////////////////////////////////////////////////////////////// -bool File::append (const std::string& name, const std::string& contents) -{ - std::ofstream out (expand (name).c_str (), - std::ios_base::out | std::ios_base::app); - if (out.good ()) - { - out << contents; - out.close (); - return true; - } - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -bool File::append ( - const std::string& name, - const std::vector & lines, - bool addNewlines /* = true */) -{ - std::ofstream out (expand (name).c_str (), - std::ios_base::out | std::ios_base::app); - if (out.good ()) - { - for (auto& line : lines) - { - out << line; - - if (addNewlines) - out << "\n"; - } - - out.close (); - return true; - } - - return false; -} - //////////////////////////////////////////////////////////////////////////////// bool File::remove (const std::string& name) { @@ -820,11 +724,6 @@ Directory::Directory (const std::string& in) { } -//////////////////////////////////////////////////////////////////////////////// -Directory::~Directory () -{ -} - //////////////////////////////////////////////////////////////////////////////// Directory& Directory::operator= (const Directory& other) { diff --git a/src/FS.h b/src/FS.h index 81b5c2e..78cf104 100644 --- a/src/FS.h +++ b/src/FS.h @@ -38,7 +38,6 @@ public: Path (); Path (const Path&); Path (const std::string&); - virtual ~Path (); Path& operator= (const Path&); bool operator== (const Path&); @@ -81,7 +80,6 @@ public: virtual bool remove () const; bool open (); - bool openAndLock (); void close (); bool lock (); @@ -90,11 +88,9 @@ public: void read (std::string&); void read (std::vector &); - void write (const std::string&); - void write (const std::vector &); - void append (const std::string&); void append (const std::vector &); + void write_raw (const std::string&); void truncate (); @@ -105,13 +101,10 @@ public: virtual time_t btime () const; static bool create (const std::string&, int mode = 0640); - static std::string read (const std::string&); static bool read (const std::string&, std::string&); static bool read (const std::string&, std::vector &); static bool write (const std::string&, const std::string&); static bool write (const std::string&, const std::vector &, bool addNewlines = true); - static bool append (const std::string&, const std::string&); - static bool append (const std::string&, const std::vector &, bool addNewlines = true); static bool remove (const std::string&); private: @@ -128,7 +121,6 @@ public: Directory (const File&); Directory (const Path&); Directory (const std::string&); - virtual ~Directory (); Directory& operator= (const Directory&); @@ -147,8 +139,6 @@ private: bool remove_directory (const std::string&) const; }; -std::ostream& operator<< (std::ostream&, const Path&); - #endif ////////////////////////////////////////////////////////////////////////////////