diff --git a/src/Errors.h b/src/Errors.h index 5cd753fb7..6d547ca31 100644 --- a/src/Errors.h +++ b/src/Errors.h @@ -7,7 +7,7 @@ /* NOTE: When changing these, remember to keep Logger.C up to date! */ enum ERRORS_ALL { ERROR_BASE = 0xCCDED000UL, - ERR_END_OF_STREAM, + ERR_END_OF_STREAM, ERR_NOT_SUPPORTED, ERR_INVALID_ARGUMENT, /* Ogg stream decoding errors */ OGG_ERR_INVALID_SIG, OGG_ERR_VERSION, diff --git a/src/Logger.c b/src/Logger.c index 057354047..b446f29d5 100644 --- a/src/Logger.c +++ b/src/Logger.c @@ -73,9 +73,11 @@ void Logger_OldWarn2(ReturnCode res, const char* place, const String* path) { /* Returns a description for ClassiCube specific error codes */ static const char* Logger_GetCCErrorDesc(ReturnCode res) { switch (res) { - case ERR_END_OF_STREAM: return "End of stream"; - case OGG_ERR_INVALID_SIG: return "Invalid OGG signature"; - case OGG_ERR_VERSION: return "Invalid OGG format version"; + case ERR_END_OF_STREAM: return "End of stream"; + case ERR_NOT_SUPPORTED: return "Operation not supported"; + case ERR_INVALID_ARGUMENT: return "Invalid argument"; + case OGG_ERR_INVALID_SIG: return "Invalid OGG signature"; + case OGG_ERR_VERSION: return "Invalid OGG format version"; case WAV_ERR_STREAM_HDR: return "Invalid WAV header"; case WAV_ERR_STREAM_TYPE: return "Invalid WAV type"; diff --git a/src/Platform.c b/src/Platform.c index d2a6e7aed..58c4a7f28 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -7,6 +7,7 @@ #include "Bitmap.h" #include "Window.h" #include "Utils.h" +#include "Errors.h" #define CC_BUILD_FREETYPE #if defined CC_BUILD_WIN @@ -37,9 +38,7 @@ static HANDLE heap; const char* Platform_NewLine = "\r\n"; const ReturnCode ReturnCode_FileShareViolation = ERROR_SHARING_VIOLATION; -const ReturnCode ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND; -const ReturnCode ReturnCode_NotSupported = ERROR_NOT_SUPPORTED; -const ReturnCode ReturnCode_InvalidArg = ERROR_INVALID_PARAMETER; +const ReturnCode ReturnCode_FileNotFound = ERROR_FILE_NOT_FOUND; const ReturnCode ReturnCode_SocketInProgess = WSAEINPROGRESS; const ReturnCode ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK; #elif defined CC_BUILD_POSIX @@ -68,9 +67,7 @@ const ReturnCode ReturnCode_SocketWouldBlock = WSAEWOULDBLOCK; const char* Platform_NewLine = "\n"; const ReturnCode ReturnCode_FileShareViolation = 1000000000; /* TODO: not used apparently */ -const ReturnCode ReturnCode_FileNotFound = ENOENT; -const ReturnCode ReturnCode_NotSupported = EPERM; -const ReturnCode ReturnCode_InvalidArg = EINVAL; +const ReturnCode ReturnCode_FileNotFound = ENOENT; const ReturnCode ReturnCode_SocketInProgess = EINPROGRESS; const ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK; #endif @@ -1353,7 +1350,7 @@ ReturnCode Socket_Available(SocketHandle socket, uint32_t* available) { } ReturnCode Socket_SetBlocking(SocketHandle socket, bool blocking) { #if defined CC_BUILD_WEB - return ReturnCode_NotSupported; /* sockets always async */ + return ERR_NOT_SUPPORTED; /* sockets always async */ #else int blocking_raw = blocking ? 0 : -1; return Socket_ioctl(socket, FIONBIO, &blocking_raw); @@ -1545,8 +1542,8 @@ bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return Platform_DescribeError(res, dst); } #elif defined CC_BUILD_WEB -ReturnCode Process_GetExePath(String* path) { return ReturnCode_NotSupported; } -ReturnCode Process_Start(const String* path, const String* args) { return ReturnCode_NotSupported; } +ReturnCode Process_GetExePath(String* path) { return ERR_NOT_SUPPORTED; } +ReturnCode Process_Start(const String* path, const String* args) { return ERR_NOT_SUPPORTED; } ReturnCode Process_StartOpen(const String* args) { char str[600]; @@ -1555,8 +1552,8 @@ ReturnCode Process_StartOpen(const String* args) { } void Process_Exit(ReturnCode code) { exit(code); } -ReturnCode DynamicLib_Load(const String* path, void** lib) { return ReturnCode_NotSupported; } -ReturnCode DynamicLib_Get(void* lib, const char* name, void** symbol) { return ReturnCode_NotSupported; } +ReturnCode DynamicLib_Load(const String* path, void** lib) { return ERR_NOT_SUPPORTED; } +ReturnCode DynamicLib_Get(void* lib, const char* name, void** symbol) { return ERR_NOT_SUPPORTED; } bool DynamicLib_DescribeError(ReturnCode res, String* dst) { return false; } #elif defined CC_BUILD_POSIX ReturnCode Process_Start(const String* path, const String* args) { @@ -1623,7 +1620,7 @@ ReturnCode Process_GetExePath(String* path) { char str[600]; int len = 600; - if (_NSGetExecutablePath(str, &len) != 0) return ReturnCode_InvalidArg; + if (_NSGetExecutablePath(str, &len)) return ERR_INVALID_ARGUMENT; Convert_DecodeUtf8(path, str, len); return 0; } @@ -1906,10 +1903,10 @@ int Platform_GetCommandLineArgs(int argc, STRING_REF const char** argv, String* } ReturnCode Platform_Encrypt(const uint8_t* data, int len, uint8_t** enc, int* encLen) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } ReturnCode Platform_Decrypt(const uint8_t* data, int len, uint8_t** dec, int* decLen) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } bool Platform_DescribeError(ReturnCode res, String* dst) { diff --git a/src/Platform.h b/src/Platform.h index ade67253b..dedf1ef79 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -27,10 +27,8 @@ enum File_SeekFrom { FILE_SEEKFROM_BEGIN, FILE_SEEKFROM_CURRENT, FILE_SEEKFROM_E extern const char* Platform_NewLine; extern const ReturnCode ReturnCode_FileShareViolation; extern const ReturnCode ReturnCode_FileNotFound; -extern const ReturnCode ReturnCode_NotSupported; extern const ReturnCode ReturnCode_SocketInProgess; extern const ReturnCode ReturnCode_SocketWouldBlock; -extern const ReturnCode ReturnCode_InvalidArg; /* Encodes a string in platform specific format. (e.g. unicode on windows, UTF8 on linux) */ /* NOTE: Only useful for platform specific function calls - do NOT try to interpret the data. */ diff --git a/src/Resources.c b/src/Resources.c index af15952d2..44beabb6e 100644 --- a/src/Resources.c +++ b/src/Resources.c @@ -734,7 +734,7 @@ CC_NOINLINE static bool Fetcher_Get(const String* id, struct HttpRequest* req) { Fetcher_Finish(); return false; } else if (!req->Data) { - Fetcher_Error = ReturnCode_InvalidArg; + Fetcher_Error = ERR_INVALID_ARGUMENT; Fetcher_Finish(); return false; } diff --git a/src/Stream.c b/src/Stream.c index 188411a12..928f602cb 100644 --- a/src/Stream.c +++ b/src/Stream.c @@ -37,10 +37,10 @@ ReturnCode Stream_Write(struct Stream* s, const uint8_t* buffer, uint32_t count) } static ReturnCode Stream_DefaultRead(struct Stream* s, uint8_t* data, uint32_t count, uint32_t* modified) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } static ReturnCode Stream_DefaultWrite(struct Stream* s, const uint8_t* data, uint32_t count, uint32_t* modified) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } ReturnCode Stream_DefaultReadU8(struct Stream* s, uint8_t* data) { uint32_t modified; @@ -64,10 +64,10 @@ static ReturnCode Stream_DefaultSkip(struct Stream* s, uint32_t count) { } static ReturnCode Stream_DefaultSeek(struct Stream* s, uint32_t pos) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } static ReturnCode Stream_DefaultGet(struct Stream* s, uint32_t* value) { - return ReturnCode_NotSupported; + return ERR_NOT_SUPPORTED; } static ReturnCode Stream_DefaultClose(struct Stream* s) { return 0; } @@ -179,7 +179,7 @@ static ReturnCode Stream_PortionSkip(struct Stream* s, uint32_t count) { struct Stream* source; ReturnCode res; - if (count > s->Meta.Portion.Left) return ReturnCode_InvalidArg; + if (count > s->Meta.Portion.Left) return ERR_INVALID_ARGUMENT; source = s->Meta.Portion.Source; res = source->Skip(source, count); @@ -241,7 +241,7 @@ static ReturnCode Stream_MemoryWrite(struct Stream* s, const uint8_t* data, uint } static ReturnCode Stream_MemorySkip(struct Stream* s, uint32_t count) { - if (count > s->Meta.Mem.Left) return ReturnCode_InvalidArg; + if (count > s->Meta.Mem.Left) return ERR_INVALID_ARGUMENT; s->Meta.Mem.Cur += count; s->Meta.Mem.Left -= count; @@ -249,7 +249,7 @@ static ReturnCode Stream_MemorySkip(struct Stream* s, uint32_t count) { } static ReturnCode Stream_MemorySeek(struct Stream* s, uint32_t position) { - if (position >= s->Meta.Mem.Length) return ReturnCode_InvalidArg; + if (position >= s->Meta.Mem.Length) return ERR_INVALID_ARGUMENT; s->Meta.Mem.Cur = s->Meta.Mem.Base + position; s->Meta.Mem.Left = s->Meta.Mem.Length - position; diff --git a/src/Vorbis.c b/src/Vorbis.c index f9d3c116c..ed39719af 100644 --- a/src/Vorbis.c +++ b/src/Vorbis.c @@ -1103,7 +1103,7 @@ static ReturnCode Vorbis_CheckHeader(struct VorbisState* ctx, uint8_t type) { OK = header[1] == 'v' && header[2] == 'o' && header[3] == 'r' && header[4] == 'b' && header[5] == 'i' && header[6] == 's'; - return OK ? 0 : ReturnCode_InvalidArg; + return OK ? 0 : ERR_INVALID_ARGUMENT; } static ReturnCode Vorbis_DecodeIdentifier(struct VorbisState* ctx) {