Winsock needs to be initialized.
[dftpd.git] / IO.cpp
blob86c853dfc9eb30d9031f335efbab6c348c72bfc4
1 #include <sys/stat.h>
2 #include <unistd.h>
3 #include <sys/stat.h>
4 #include "IO.hpp"
7 #ifdef _WIN32
9 bool IO::MkDir( const std::string& dir )
11 return CreateDirectory( dir.c_str(), NULL ) != 0;
14 bool IO::RmDir( const std::string& dir )
16 return RemoveDirectory( dir.c_str() ) != 0;
19 Directory::Directory()
20 : m_handle( INVALID_HANDLE_VALUE )
24 Directory::~Directory()
26 if( m_handle != INVALID_HANDLE_VALUE )
28 FindClose( m_handle );
32 bool Directory::Open( const std::string& dir )
34 m_path = dir + "\\*";
35 m_handle = FindFirstFile( m_path.c_str(), &m_ffd );
37 return m_handle != INVALID_HANDLE_VALUE;
40 std::string Directory::GetName()
42 return m_ffd.cFileName;
45 Directory& Directory::operator++()
47 if( FindNextFile( m_handle, &m_ffd ) == 0 )
49 FindClose( m_handle );
50 m_handle = INVALID_HANDLE_VALUE;
52 return *this;
55 Directory::operator bool()
57 return m_handle != INVALID_HANDLE_VALUE;
60 #else
62 bool IO::MkDir( const std::string& dir )
64 return mkdir( dir.c_str(), S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ) == 0;
67 bool IO::RmDir( const std::string& dir )
69 return rmdir( dir.c_str() ) == 0;
72 Directory::Directory()
73 : m_dir( NULL )
77 Directory::~Directory()
79 closedir( m_dir );
82 bool Directory::Open( const std::string& dir )
84 m_dir = opendir( dir.c_str() );
85 m_dirent = readdir( m_dir );
87 return m_dir != NULL;
90 std::string Directory::GetName()
92 return m_dirent->d_name;
95 Directory& Directory::operator++()
97 m_dirent = readdir( m_dir );
98 return *this;
101 Directory::operator bool()
103 return m_dirent != NULL;
106 #endif