#pragma once
#include "../string/String.hpp"
#include <stdio.h>
namespace sprawl
{
namespace filesystem
{
char const* LineSeparator();
char const* NullDevice();
void Chdir(String const& path);
String GetCwd();
enum class RelativeTo
{
Beginning,
CurrentPosition,
End,
};
class File
{
public:
File(FILE* file, sprawl::String const& mode)
: m_file(file)
, m_mode(mode)
, m_refCount(new std::atomic<int>(1))
{
//
}
File()
: m_file(nullptr)
, m_mode()
, m_refCount(nullptr)
{
//
}
File(File const& other);
void operator=(File const& other);
~File();
void Close();
void Sync();
void Flush();
int FileNo();
bool IsATTY();
String Read(int numBytes = -1);
String ReadLine(int numBytes = -1);
void Seek(int offset, RelativeTo relativeTo);
int Tell();
void Truncate(int size = -1);
void Write(String const& str);
bool IsClosed();
String const& Mode();
int FileSize();
private:
FILE* m_file;
String m_mode;
std::atomic<int>* m_refCount;
};
File Open(String const& path, char const* const mode);
/// @todo:
bool Mkdir(String const& path, int mode);
bool MakeDirs(String const& path, int mode);
bool Remove(String const& path);
bool RemoveDirs(String const& path);
bool Rename(String const& path, String const& newName);
bool Renames(String const& path, String const& newName);
bool RmDir(String const& path);
bool RmTree(String const& path);
String TempName(String const& dir = "", String const& path = "");
/// @todo - access(), chmod(), chflags(), stat()
/// @todo - environment variables, getpid, umask, listdir, lstat, readlink
}
}
| # | Change | User | Description | Committed | |
|---|---|---|---|---|---|
| #6 | 16131 | ShadauxCat |
- Exposed FILE* object in sprawl::filesystem::File - Added ability to specify flush behavior for custom handlers via std::function (interesting note - apparently with optimization enabled, calls to std::function can execute faster than virtual function calls) - Threads that destruct with no Join() after exiting with an uncaught exception will terminate with an error message rather than swallowing the exception and letting it disappear #review-16132 |
||
| #5 | 14822 | ShadauxCat |
Last batch of filesystem code for now, added MakeSymlink and GetPid, removed other todo functions for the time being. Also fixed some bugs: -Linux IsLink() implementation not using lstat = broken -File::IsClosed() would crash if file were created via default constructor or null handle -Remove() and RmDir() on Windows were inconsistent with Linux - in Linux all symlinks are removed with Remove() even if they point to directories. Forced windows to work the same way. -Asked RmTree to please not descend into symbolic links to directories, but just to remove them, thanks. -Removed starting \\?\ from result of RealPath() on Windows -Fixed IsFile() on Windows just not working - assuming anything that's not a directory is a file now. -Fixed StringBuilder only printing the first character if you passed it type char* instead of type char const* #review-14823 |
||
| #4 | 14816 | ShadauxCat |
Filled in some more filesystem functions, added appropriate unit tests. Only a few remain. #review-14817 |
||
| #3 | 14781 | ShadauxCat |
-Finished path library -Added some more functionality to filesystem library -Added a few more unit tests, still more needed for path #review-14782 |
||
| #2 | 14761 | ShadauxCat |
First drop of code for sprawl::filesystem and sprawl::path. Library will continue to grow. Also fixed a warning on linux. #review-14762 |
||
| #1 | 12508 | ShadauxCat |
-Added threading library. Currently only functional for Linux; Windows will fail to link. (I will fix this soon.) -Fixed missing move and copy constructors in List and ForwardList -Fixed broken move constructor in HashMap -Fixed missing const get() in HashMap -Fixed broken operator-> in ListIterator -Added sprawl::noncopyable -Added sketch headers for filesystem library -Made StringLiteral hashable, added special hashes for pointers and integers in murmur3 -Fixed compiler warning in async_network -Updated memory allocators to use new threading library for mutexes -Added accessibility to sprawl::StringLiteral to be able toa ccess its pointer and length and perform pointer comparisons #review-12504 |