Spectre/System/File: add getErrorMessage()
This commit is contained in:
parent
59a4f1347a
commit
dc04a12922
2 changed files with 21 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <system_error>
|
||||
#include <Spectre/System/File.h>
|
||||
|
||||
namespace sp {
|
||||
|
|
@ -54,6 +55,7 @@ bool File::open(const std::string& filename, Access access, unsigned int mode)
|
|||
if (mode & CREATE && (access == Access::WRITE || access == Access::READ_WRITE)) {
|
||||
m_handle = fopen(filename.c_str(), "a");
|
||||
if (!m_handle) {
|
||||
m_error.assign(errno, std::generic_category());
|
||||
return false;
|
||||
}
|
||||
fclose(m_handle);
|
||||
|
|
@ -70,12 +72,18 @@ bool File::open(const std::string& filename, Access access, unsigned int mode)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
m_error.assign(errno, std::generic_category());
|
||||
return false;
|
||||
}
|
||||
|
||||
bool File::isOpen() const
|
||||
{
|
||||
return m_handle != NULL;
|
||||
if (m_handle == NULL) {
|
||||
m_error = std::errc::bad_file_descriptor;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void File::close()
|
||||
|
|
@ -84,6 +92,12 @@ void File::close()
|
|||
fclose(m_handle);
|
||||
m_handle = NULL;
|
||||
}
|
||||
m_error.clear();
|
||||
}
|
||||
|
||||
std::string File::getErrorMessage() const
|
||||
{
|
||||
return m_error.message();
|
||||
}
|
||||
|
||||
size_t File::pos()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue