summaryrefslogtreecommitdiff
path: root/src/error.h
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2012-05-21 16:50:15 +0400
committerAndrey Nazarov <skuller@skuller.net>2012-05-21 16:50:15 +0400
commiteb99b2fb254a29e71ece43a78d7bf5026a32725c (patch)
tree04e8de8bb891b1f985d64663d78f7d68cfba1fc8 /src/error.h
parentffecb24206036838a1c4ea5db79e3548b6619486 (diff)
Evaluate errno once when converting to qerror_t.
On some systems errno is defined as a function. That breaks the assumption that Q_ERR(errno) macro always returns error value (i.e., less than zero), making the compiler complain about uninitialized variables. Fix this by adding Q_Errno wrapper around Q_ERR(errno) that evaluates errno exactly once.
Diffstat (limited to 'src/error.h')
-rw-r--r--src/error.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/error.h b/src/error.h
index 41f9ff8..ea649f6 100644
--- a/src/error.h
+++ b/src/error.h
@@ -28,6 +28,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define _Q_ERR(e) (-ERRNO_MAX - e)
+// These values are extensions to system errno.
#define Q_ERR_SUCCESS 0 // Success
#define Q_ERR_FAILURE _Q_ERR(0) // Unspecified error
#define Q_ERR_UNKNOWN_FORMAT _Q_ERR(1) // Unknown file format
@@ -52,6 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define Q_ERR_NOT_COHERENT _Q_ERR(19) // Coherency check failed
#endif
+// These values directly map to system errno.
#define Q_ERR_NOENT Q_ERR(ENOENT)
#define Q_ERR_NAMETOOLONG Q_ERR(ENAMETOOLONG)
#define Q_ERR_INVAL Q_ERR(EINVAL)
@@ -67,4 +69,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define Q_PrintError(what, code) \
Com_Printf("Couldn't %s: %s\n", what, Q_ErrorString(code))
+// Maps system error to qerror_t, evaluating errno exactly once.
+// Useful for platforms where errno is defined as a function (e.g. Win32).
+// This function always returns error value (i.e., less than zero).
+static inline qerror_t Q_Errno(void)
+{
+ int e = errno;
+
+ return Q_ERR(e);
+}
+
const char *Q_ErrorString(qerror_t error);