Skip to content

Commit

Permalink
Merge remote-tracking branch 'robux4/del_crterror'
Browse files Browse the repository at this point in the history
  • Loading branch information
mbunkus committed Feb 24, 2024
2 parents 209ad33 + 6d732f1 commit e735b44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 36 deletions.
17 changes: 0 additions & 17 deletions ebml/StdIOCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@

#include "IOCallback.h"

#include <stdexcept>
#include <cerrno>

namespace libebml {

enum open_mode {
Expand All @@ -21,20 +18,6 @@ enum open_mode {
MODE_SAFE
};

class EBML_DLL_API CRTError:public std::runtime_error
{
// Variablen...
private:
int Error;

// Methoden...
public:
CRTError(int Error,const std::string&Description);
explicit CRTError(const std::string&Description,int Error=errno);

int getError() const noexcept { return Error; }
};

// This class is currently private to the library, so there's no MATROSKA_EXPORT.
class EBML_DLL_API StdIOCallback:public IOCallback
{
Expand Down
4 changes: 2 additions & 2 deletions src/EbmlBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
\author Julien Coloos <suiryc @ users.sf.net>
*/
#include <string>
#include <stdexcept>

#include "ebml/EbmlBinary.h"
#include "ebml/StdIOCallback.h"

namespace libebml {

Expand Down Expand Up @@ -85,7 +85,7 @@ filepos_t EbmlBinary::ReadData(IOCallback & input, ScopeMode ReadFully)

Data = (GetSize() < std::numeric_limits<std::size_t>::max()) ? static_cast<binary *>(malloc(GetSize())) : nullptr;
if (Data == nullptr)
throw CRTError(std::string("Error allocating data"));
throw std::runtime_error("Error allocating data");
SetValueIsSet();
return input.read(Data, GetSize());
}
Expand Down
22 changes: 5 additions & 17 deletions src/StdIOCallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,14 @@
#include <limits>
#include <sstream>
#include <cstring>
#include <ios>

#include "ebml/StdIOCallback.h"

using namespace std;

namespace libebml {

CRTError::CRTError(int nError, const std::string & Description)
:std::runtime_error(Description+": "+strerror(nError))
,Error(nError)
{
}

CRTError::CRTError(const std::string & Description,int nError)
:std::runtime_error(Description+": "+strerror(nError))
,Error(nError)
{
}


StdIOCallback::StdIOCallback(const char*Path, const open_mode aMode)
{
assert(Path!=nullptr);
Expand All @@ -57,7 +45,7 @@ StdIOCallback::StdIOCallback(const char*Path, const open_mode aMode)
if(File==nullptr) {
stringstream Msg;
Msg<<"Can't open stdio file \""<<Path<<"\" in mode \""<<Mode<<"\"";
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}
mCurrentPosition = 0;
}
Expand Down Expand Up @@ -91,7 +79,7 @@ void StdIOCallback::setFilePointer(std::int64_t Offset,seek_mode Mode)
if(fseek(File,Offset,Mode)!=0) {
ostringstream Msg;
Msg<<"Failed to seek file "<<File<<" to offset "<<Offset<<" in mode "<<Mode;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}

switch ( Mode ) {
Expand Down Expand Up @@ -124,7 +112,7 @@ std::uint64_t StdIOCallback::getFilePointer()
if(Result<0) {
stringstream Msg;
Msg<<"Can't tell the current file pointer position for "<<File;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}
#endif

Expand All @@ -139,7 +127,7 @@ void StdIOCallback::close()
if(fclose(File)!=0) {
stringstream Msg;
Msg<<"Can't close file "<<File;
throw CRTError(Msg.str());
throw ios_base::failure(Msg.str(), error_code{errno, std::system_category()});
}

File=nullptr;
Expand Down

0 comments on commit e735b44

Please sign in to comment.