AGS: Change Allegro error codes to avoid clash on some systems

This commit is contained in:
Paul Gilbert 2021-02-06 18:59:20 -08:00
parent 9e474be88a
commit 8d62c2faf6
10 changed files with 68 additions and 72 deletions

View File

@ -91,7 +91,7 @@ int File_Delete(const char *fnmm) {
if (::remove(rp.FullPath) == 0)
return 1;
if (errnum == ENOENT && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
if (errnum == AL_ENOENT && !rp.AltPath.IsEmpty() && rp.AltPath.Compare(rp.FullPath) != 0)
return ::remove(rp.AltPath) == 0 ? 1 : 0;
return 0;
}

View File

@ -73,7 +73,7 @@ struct AGSPlatformDriver
virtual void DisplayAlert(const char *, ...) = 0;
virtual void AttachToParentConsole();
virtual int GetLastSystemError() {
return errnum;
return (int)errnum;
}
// Get root directory for storing per-game shared data
virtual const char *GetAllUsersDataDirectory() {

View File

@ -104,10 +104,10 @@ size_t BuildXDGPath(char *destPath, size_t destSize) {
// No evironment variable, so we fall back to home dir in /etc/passwd
struct passwd *p = getpwuid(getuid());
l = snprintf(destPath, destSize, "%s/.local", p->pw_dir);
if (mkdir(destPath, 0755) != 0 && errnum != EEXIST)
if (mkdir(destPath, 0755) != 0 && errnum != AL_EEXIST)
return 0;
l += snprintf(destPath + l, destSize - l, "/share");
if (mkdir(destPath, 0755) != 0 && errnum != EEXIST)
if (mkdir(destPath, 0755) != 0 && errnum != AL_EEXIST)
return 0;
}
return l;

View File

@ -109,7 +109,7 @@ PALETTE default_palette = {
int install_allegro() {
errnum = 0;
errnum = AL_NOERROR;
return 0;
}

View File

@ -26,6 +26,7 @@
#include "common/scummsys.h"
#include "common/algorithm.h"
#include "common/endian.h"
#include "ags/lib/allegro/error.h"
namespace AGS3 {
@ -43,8 +44,6 @@ namespace AGS3 {
#define AL_ID MKTAG
extern int *allegro_errno;
/**
* info about a hardware driver
*/

View File

@ -24,7 +24,7 @@
namespace AGS3 {
int errnum;
int *allegro_errno = &errnum;
AllegroError errnum;
AllegroError *allegro_errno = &errnum;
} // namespace AGS3

View File

@ -28,53 +28,50 @@
namespace AGS3 {
// Error codes
#define EPERM 1
#define ENOENT 2
#define ESRCH 3
#define EINTR 4
#define EIO 5
#define ENXIO 6
#define E2BIG 7
#define ENOEXEC 8
#define EBADF 9
#define ECHILD 10
#define EAGAIN 11
#define ENOMEM 12
#define EACCES 13
#define EFAULT 14
#define EBUSY 16
#define EEXIST 17
#define EXDEV 18
#define ENODEV 19
#define ENOTDIR 20
#define EISDIR 21
#define ENFILE 23
#define EMFILE 24
#define ENOTTY 25
#define EFBIG 27
#define ENOSPC 28
#define ESPIPE 29
#define EROFS 30
#define EMLINK 31
#define EPIPE 32
#define EDOM 33
#define EDEADLK 36
#define ENAMETOOLONG 38
#define ENOLCK 39
#define ENOSYS 40
#define ENOTEMPTY 41
enum AllegroError {
AL_NOERROR = 0,
AL_EPERM = 1,
AL_ENOENT = 2,
AL_ESRCH = 3,
AL_EINTR = 4,
AL_EIO = 5,
AL_ENXIO = 6,
AL_E2BIG = 7,
AL_ENOEXEC = 8,
AL_EBADF = 9,
AL_ECHILD = 10,
AL_EAGAIN = 11,
AL_ENOMEM = 12,
AL_EACCES = 13,
AL_EFAULT = 14,
AL_EBUSY = 16,
AL_EEXIST = 17,
AL_EXDEV = 18,
AL_ENODEV = 19,
AL_ENOTDIR = 20,
AL_EISDIR = 21,
AL_EINVAL = 22,
AL_ENFILE = 23,
AL_EMFILE = 24,
AL_ENOTTY = 25,
AL_EFBIG = 27,
AL_ENOSPC = 28,
AL_ESPIPE = 29,
AL_EROFS = 30,
AL_EMLINK = 31,
AL_EPIPE = 32,
AL_EDOM = 33,
AL_ERANGE = 34,
AL_EDEADLK = 36,
AL_ENAMETOOLONG = 38,
AL_ENOLCK = 39,
AL_ENOSYS = 40,
AL_ENOTEMPTY = 41,
AL_EILSEQ = 42
};
// Error codes used in the Secure CRT functions
#ifndef RC_INVOKED
#define _SECURECRT_ERRCODE_VALUES_DEFINED
#define EINVAL 22
#define ERANGE 34
#define EILSEQ 42
#define STRUNCATE 80
#endif
extern int errnum;
extern int *allegro_errno;
extern AllegroError errnum;
extern AllegroError *allegro_errno;
} // namespace AGS3

View File

@ -30,12 +30,12 @@ fixed radtofix_r;
fixed ftofix(double x) {
if (x > 32767.0) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x7FFFFFFF;
}
if (x < -32767.0) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return (fixed) - 0x7FFFFFFF;
}
@ -51,13 +51,13 @@ fixed fixadd(fixed x, fixed y) {
if (result >= 0) {
if ((x < 0) && (y < 0)) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return (fixed) - 0x7FFFFFFF;
} else
return result;
} else {
if ((x > 0) && (y > 0)) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x7FFFFFFF;
} else
return result;
@ -69,13 +69,13 @@ fixed fixsub(fixed x, fixed y) {
if (result >= 0) {
if ((x < 0) && (y > 0)) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return (fixed) - 0x7FFFFFFF;
} else
return result;
} else {
if ((x > 0) && (y < 0)) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x7FFFFFFF;
} else
return result;
@ -88,10 +88,10 @@ fixed fixmul(fixed x, fixed y) {
int64 lres = (lx * ly);
if (lres > 0x7FFFFFFF0000LL) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x7FFFFFFF;
} else if (lres < -0x7FFFFFFF0000LL) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x80000000;
} else {
int res = lres >> 16;
@ -101,7 +101,7 @@ fixed fixmul(fixed x, fixed y) {
fixed fixdiv(fixed x, fixed y) {
if (y == 0) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return (fixed)(x < 0) ? -0x7FFFFFFF : 0x7FFFFFFF;
} else
return ftofix(fixtof(x) / fixtof(y));
@ -118,7 +118,7 @@ int fixfloor(fixed x) {
int fixceil(fixed x) {
if (x > 0x7FFF0000) {
*allegro_errno = ERANGE;
*allegro_errno = AL_ERANGE;
return 0x7FFF;
}
@ -152,7 +152,7 @@ fixed fixtan(fixed x) {
fixed fixacos(fixed x) {
if ((x < -65536) || (x > 65536)) {
*allegro_errno = EDOM;
*allegro_errno = AL_EDOM;
return 0;
}
@ -162,7 +162,7 @@ fixed fixacos(fixed x) {
fixed fixasin(fixed x) {
if ((x < -65536) || (x > 65536)) {
*allegro_errno = EDOM;
*allegro_errno = AL_EDOM;
return 0;
}

View File

@ -248,17 +248,17 @@ fixed fixatan2(fixed y, fixed x) {
if (x == 0) {
if (y == 0) {
*allegro_errno = EDOM;
*allegro_errno = AL_EDOM;
return 0L;
} else
return ((y < 0) ? -0x00400000L : 0x00400000L);
}
*allegro_errno = 0;
*allegro_errno = AL_NOERROR;
r = fixdiv(y, x);
if (*allegro_errno) {
*allegro_errno = 0;
*allegro_errno = AL_NOERROR;
return ((y < 0) ? -0x00400000L : 0x00400000L);
}

View File

@ -59,11 +59,11 @@ StrUtil::ConversionError StrUtil::StringToInt(const String &s, int &val, int def
if (!s.GetCStr())
return StrUtil::kFailed;
char *stop_ptr;
errnum = 0;
errnum = AL_NOERROR;
long lval = strtol(s.GetCStr(), &stop_ptr, 0);
if (stop_ptr != s.GetCStr() + s.GetLength())
return StrUtil::kFailed;
if (lval > INT_MAX || lval < INT_MIN || errnum == ERANGE)
if (lval > INT_MAX || lval < INT_MIN || errnum == AL_ERANGE)
return StrUtil::kOutOfRange;
val = (int)lval;
return StrUtil::kNoError;