Skip to content

Commit

Permalink
Tidy and extend Utils::MapLastError()
Browse files Browse the repository at this point in the history
Added a new KErrCorrupt error to MapLastError() and made the different
platform versions consistent in their naming.
  • Loading branch information
Colin Ward committed Nov 18, 2023
1 parent a8997f0 commit 4588b87
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,25 @@ TInt Utils::MapLastError()

#ifdef __amigaos__

LONG Result;
int Error = IoErr();

Result = IoErr();

if (Result == ERROR_OBJECT_EXISTS)
if (Error == ERROR_OBJECT_EXISTS)
{
RetVal = KErrAlreadyExists;
}
else if (Result == ERROR_OBJECT_NOT_FOUND)
else if (Error == ERROR_DIR_NOT_FOUND)
{
RetVal = KErrPathNotFound;
}
else if (Error == ERROR_OBJECT_NOT_FOUND)
{
RetVal = KErrNotFound;
}
else if (Result == ERROR_DIR_NOT_FOUND)
else if (Error == ERROR_OBJECT_WRONG_TYPE)
{
RetVal = KErrPathNotFound;
RetVal = KErrCorrupt;
}
else if ((Result == ERROR_DIRECTORY_NOT_EMPTY) || (Result == ERROR_OBJECT_IN_USE))
else if ((Error == ERROR_DIRECTORY_NOT_EMPTY) || (Error == ERROR_OBJECT_IN_USE))
{
RetVal = KErrInUse;
}
Expand All @@ -202,40 +204,44 @@ TInt Utils::MapLastError()

#elif defined(__unix__)

if (errno == EEXIST)
int Error = errno;

if (Error == EEXIST)
{
RetVal = KErrAlreadyExists;
}
else if (errno == ENOENT)
else if (Error == ENOENT)
{
RetVal = KErrNotFound;
Error = KErrNotFound;
}
else if ((errno == ENOTEMPTY) || (errno == EBUSY) || (errno == ETXTBSY))
else if ((Error == ENOTEMPTY) || (Error == EBUSY) || (Error == ETXTBSY))
{
RetVal = KErrInUse;
Error = KErrInUse;
}
else
{
RetVal = KErrGeneral;
Error = KErrGeneral;
}

#else /* ! __unix__ */

DWORD Error;

Error = GetLastError();
DWORD Error = GetLastError();

if (Error == ERROR_FILE_EXISTS)
{
RetVal = KErrAlreadyExists;
}
else if (Error == ERROR_PATH_NOT_FOUND)
{
RetVal = KErrPathNotFound;
}
else if ((Error == ERROR_FILE_NOT_FOUND) || (Error == ERROR_INVALID_NAME))
{
RetVal = KErrNotFound;
}
else if (Error == ERROR_PATH_NOT_FOUND)
else if (Error == ERROR_BAD_EXE_FORMAT)
{
RetVal = KErrPathNotFound;
RetVal = KErrCorrupt;
}
else if ((Error == ERROR_DIR_NOT_EMPTY) || (Error == ERROR_SHARING_VIOLATION))
{
Expand Down

0 comments on commit 4588b87

Please sign in to comment.