You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Brian Havard <br...@kheldar.apana.org.au> on 2000/04/02 07:10:08 UTC
Re: ap_status_t for non-unix platforms
On Sat, 1 Apr 2000 14:25:25 -0500 (EST), rbb@apache.org wrote:
[...]
>> Take a look at my proposed scheme and if you can find a significant
>> disadvantage or deficiency in it then let us know. The way I've worked
>> it, nothing needs to know about any bit mappings in Win32 error codes
>> and should work in an identical way on all platforms. In fact it's so
>> simple there must be _something_ wrong with it or we would have come up
>> with it long ago (unless we're just slow that is ;-)
>
>Brian,
>
>Unless I;ve misread your idea, it's just perfect. And, we did come up
>with it a long time ago, we just didn't take it far enough. Your idea
>should basically just add another macro that needs to be defined on each
>platform.
I think the macro can be the same on all platforms although it might be worth
optimizing it for platforms that will never pass 0 to it. I'm thinking of Win32
where
you only get an OS error code from GetLastError() after an API returns FALSE. IE on
Win32 you'd do:
#define APR_OS_STATUS(oscode) (oscode + APR_OS_START_SYSERR)
...
if (CreateFile(...))
return APR_SUCCESS;
else
return APR_OS_STATUS(GetLastError());
and on OS/2 youd do:
#define APR_OS_STATUS(oscode) (oscode ? \
oscode + APR_OS_START_SYSERR : \
APR_SUCCESS)
return APR_OS_STATUS(DosOpen(...));
and on unix you'd do:
fd = open(...);
return fd < 0 ? errno : APR_SUCCESS;
Extending on my original suggestion to incorporate what's in the current
apr_errno.h,
the ap_status_t code space would look like this.
-----------------------------------------------------------------------
| errno values | APR errors | APR status | User codes | OS error codes
-----------------------------------------------------------------------
0 4000 4500 5000 5500
| | | | |
APR_SUCCESS | | | APR_OS_START_SYSERR
| | APR_OS_START_USEERR
| APR_OS_START_STATUS
APR_OS_START_ERROR
Although we should drop the "_OS_" from these macros as they're not OS specific.
Note
that I've swapped USEERR & SYSERR making SYSERR at the end.
Here's my patch that rearranges apr_errno.h to fit with this.
Index: apr_errno.h
===================================================================
RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_errno.h,v
retrieving revision 1.16
diff -u -r1.16 apr_errno.h
--- apr_errno.h 2000/03/31 08:35:55 1.16
+++ apr_errno.h 2000/04/02 04:40:31
@@ -52,6 +52,18 @@
* <http://www.apache.org/>.
*/
+ /*
+ Map of ap_status_t code space
+ -----------------------------------------------------------------------
+ | errno values | APR errors | APR status | User codes | OS error codes
+ -----------------------------------------------------------------------
+ 0 4000 4500 5000 5500
+ | | | | |
+ APR_SUCCESS | | | APR_OS_START_SYSERR
+ | | APR_OS_START_USEERR
+ | APR_OS_START_STATUS
+ APR_OS_START_ERROR
+ */
#include <errno.h>
#if WIN32
#include "apr_win.h"
@@ -67,9 +79,9 @@
#endif /* __cplusplus */
/* Define four layers of status code offsets so that we don't interfere
- * with the predefined errno codes on the operating system. Codes beyond
- * APR_OS_START_USEERR are reserved for applications that use APR that
- * layer their own error codes along with APR's.
+ * with the predefined errno codes on the operating system. Codes between
+ * APR_USRERR_START & APR_OSERR_OFFSET are reserved for applications that use
+ * APR that layer their own error codes along with APR's.
*/
#ifndef APR_OS_START_ERROR
#define APR_OS_START_ERROR 4000
@@ -77,18 +89,21 @@
#ifndef APR_OS_START_STATUS
#define APR_OS_START_STATUS (APR_OS_START_ERROR + 500)
#endif
-#ifndef APR_OS_START_SYSERR
-#define APR_OS_START_SYSERR (APR_OS_START_STATUS + 500)
-#endif
#ifndef APR_OS_START_USEERR
-#define APR_OS_START_USEERR (APR_OS_START_SYSERR + 500)
+#define APR_OS_START_USEERR (APR_OS_START_STATUS + 500)
#endif
+#ifndef APR_OS_START_SYSERR
+#define APR_OS_START_SYSERR (APR_OS_START_USEERR + 500)
+#endif
/* If this definition of APRStatus changes, then we can remove this, but right
* now, the decision was to use an errno-like implementation.
*/
typedef int ap_status_t;
+/* Use this macro to return an ap_status_t from an OS error code */
+#define APR_OS_STATUS(oscode) (oscode ? oscode + APR_OS_START_SYSERR : APR_SUCCESS)
+
#define APR_SUCCESS 0
/* APR ERROR VALUES */
@@ -136,16 +151,16 @@
#define APR_KEYBASED (APR_OS_START_STATUS + 21)
/* A simple value to be used to initialze a status variable. */
-#define APR_EINIT (APR_OS_START_STATUS + 16)
+#define APR_EINIT (APR_OS_START_STATUS + 100)
/* Not implemented either because we haven't gotten to it yet, or
* because it is not possible to do correctly.
*/
-#define APR_ENOTIMPL (APR_OS_START_STATUS + 17)
+#define APR_ENOTIMPL (APR_OS_START_STATUS + 101)
/* Passwords do not match.
*/
-#define APR_EMISMATCH (APR_OS_START_STATUS + 18)
+#define APR_EMISMATCH (APR_OS_START_STATUS + 102)
/*
* APR equivalents to what should be standard errno codes.
@@ -153,313 +168,313 @@
#ifdef EACCES
#define APR_EACCES EACCES
#else
-#define APR_EACCES (APR_OS_START_SYSERR + 0)
+#define APR_EACCES (APR_OS_START_ERROR + 100)
#endif
#ifdef EEXIST
#define APR_EEXIST EEXIST
#else
-#define APR_EEXIST (APR_OS_START_SYSERR + 1)
+#define APR_EEXIST (APR_OS_START_ERROR + 101)
#endif
#ifdef EISDIR
#define APR_EISDIR EISDIR
#else
-#define APR_EISDIR (APR_OS_START_SYSERR + 2)
+#define APR_EISDIR (APR_OS_START_ERROR + 102)
#endif
#ifdef ENAMETOOLONG
#define APR_ENAMETOOLONG ENAMETOOLONG
#else
-#define APR_ENAMETOOLONG (APR_OS_START_SYSERR + 3)
+#define APR_ENAMETOOLONG (APR_OS_START_ERROR + 103)
#endif
#ifdef ENOENT
#define APR_ENOENT ENOENT
#else
-#define APR_ENOENT (APR_OS_START_SYSERR + 4)
+#define APR_ENOENT (APR_OS_START_ERROR + 104)
#endif
#ifdef ENOTDIR
#define APR_ENOTDIR ENOTDIR
#else
-#define APR_ENOTDIR (APR_OS_START_SYSERR + 5)
+#define APR_ENOTDIR (APR_OS_START_ERROR + 105)
#endif
#ifdef ENXIO
#define APR_ENXIO ENXIO
#else
-#define APR_ENXIO (APR_OS_START_SYSERR + 6)
+#define APR_ENXIO (APR_OS_START_ERROR + 106)
#endif
#ifdef ENODEV
#define APR_ENODEV ENODEV
#else
-#define APR_ENODEV (APR_OS_START_SYSERR + 7)
+#define APR_ENODEV (APR_OS_START_ERROR + 107)
#endif
#ifdef EROFS
#define APR_EROFS EROFS
#else
-#define APR_EROFS (APR_OS_START_SYSERR + 8)
+#define APR_EROFS (APR_OS_START_ERROR + 108)
#endif
#ifdef ETXTBSY
#define APR_ETXTBSY ETXTBSY
#else
-#define APR_ETXTBSY (APR_OS_START_SYSERR + 9)
+#define APR_ETXTBSY (APR_OS_START_ERROR + 109)
#endif
#ifdef EFAULT
#define APR_EFAULT EFAULT
#else
-#define APR_EFAULT (APR_OS_START_SYSERR + 10)
+#define APR_EFAULT (APR_OS_START_ERROR + 110)
#endif
#ifdef ELOOP
#define APR_ELOOP ELOOP
#else
-#define APR_ELOOP (APR_OS_START_SYSERR + 11)
+#define APR_ELOOP (APR_OS_START_ERROR + 111)
#endif
#ifdef ENOSPC
#define APR_ENOSPC ENOSPC
#else
-#define APR_ENOSPC (APR_OS_START_SYSERR + 12)
+#define APR_ENOSPC (APR_OS_START_ERROR + 112)
#endif
#ifdef ENONOMEM
#define APR_ENOMEM ENOMEM
#else
-#define APR_ENOMEM (APR_OS_START_SYSERR + 13)
+#define APR_ENOMEM (APR_OS_START_ERROR + 113)
#endif
#ifdef EMFILE
#define APR_EMFILE EMFILE
#else
-#define APR_EMFILE (APR_OS_START_SYSERR + 14)
+#define APR_EMFILE (APR_OS_START_ERROR + 114)
#endif
#ifdef ENFILE
#define APR_ENFILE ENFILE
#else
-#define APR_ENFILE (APR_OS_START_SYSERR + 15)
+#define APR_ENFILE (APR_OS_START_ERROR + 115)
#endif
#ifdef EBADF
#define APR_EBADF EBADF
#else
-#define APR_EBADF (APR_OS_START_SYSERR + 16)
+#define APR_EBADF (APR_OS_START_ERROR + 116)
#endif
#ifdef EPERM
#define APR_EPERM EPERM
#else
-#define APR_EPERM (APR_OS_START_SYSERR + 17)
+#define APR_EPERM (APR_OS_START_ERROR + 117)
#endif
#ifdef EIO
#define APR_EIO EIO
#else
-#define APR_EIO (APR_OS_START_SYSERR + 18)
+#define APR_EIO (APR_OS_START_ERROR + 118)
#endif
#ifdef EINVAL
#define APR_EINVAL EINVAL
#else
-#define APR_EINVAL (APR_OS_START_SYSERR + 19)
+#define APR_EINVAL (APR_OS_START_ERROR + 119)
#endif
#ifdef ENOEMPTY
#define APR_ENOEMPTY ENOEMPTY
#else
-#define APR_ENOEMPTY (APR_OS_START_SYSERR + 20)
+#define APR_ENOEMPTY (APR_OS_START_ERROR + 120)
#endif
#ifdef EBUSY
#define APR_EBUSY EBUSY
#else
-#define APR_EBUSY (APR_OS_START_SYSERR + 21)
+#define APR_EBUSY (APR_OS_START_ERROR + 121)
#endif
#ifdef ESPIPE
#define APR_ESPIPE ESPIPE
#else
-#define APR_ESPIPE (APR_OS_START_SYSERR + 22)
+#define APR_ESPIPE (APR_OS_START_ERROR + 122)
#endif
#ifdef EIDRM
#define APR_EIDRM EIDRM
#else
-#define APR_EIDRM (APR_OS_START_SYSERR + 23)
+#define APR_EIDRM (APR_OS_START_ERROR + 123)
#endif
#ifdef ERANGE
#define APR_ERANGE ERANGE
#else
-#define APR_ERANGE (APR_OS_START_SYSERR + 24)
+#define APR_ERANGE (APR_OS_START_ERROR + 124)
#endif
#ifdef E2BIG
#define APR_E2BIG E2BIG
#else
-#define APR_E2BIG (APR_OS_START_SYSERR + 25)
+#define APR_E2BIG (APR_OS_START_ERROR + 125)
#endif
#ifdef EAGAIN
#define APR_EAGAIN EAGAIN
#else
-#define APR_EAGAIN (APR_OS_START_SYSERR + 26)
+#define APR_EAGAIN (APR_OS_START_ERROR + 126)
#endif
#ifdef EFBIG
#define APR_EFBIG EFBIG
#else
-#define APR_EFBIG (APR_OS_START_SYSERR + 27)
+#define APR_EFBIG (APR_OS_START_ERROR + 127)
#endif
#ifdef EINTR
#define APR_EINTR EINTR
#else
-#define APR_EINTR (APR_OS_START_SYSERR + 28)
+#define APR_EINTR (APR_OS_START_ERROR + 128)
#endif
#ifdef EDEADLK
#define APR_EDEADLK EDEADLK
#else
-#define APR_EDEADLK (APR_OS_START_SYSERR + 29)
+#define APR_EDEADLK (APR_OS_START_ERROR + 129)
#endif
#ifdef ENOLCK
#define APR_ENOLCK ENOLCK
#else
-#define APR_ENOLCK (APR_OS_START_SYSERR + 30)
+#define APR_ENOLCK (APR_OS_START_ERROR + 130)
#endif
#ifdef EWOULDBLOCK
#define APR_EWOULDBLOCK EWOULDBLOCK
#else
-#define APR_EWOULDBLOCK (APR_OS_START_SYSERR + 31)
+#define APR_EWOULDBLOCK (APR_OS_START_ERROR + 131)
#endif
#ifdef EPROTONOSUPPORT
#define APR_EPROTONOSUPPORT EPROTONOSUPPORT
#else
-#define APR_EPROTONOSUPPORT (APR_OS_START_SYSERR + 32)
+#define APR_EPROTONOSUPPORT (APR_OS_START_ERROR + 132)
#endif
#ifdef ENOTSOCK
#define APR_ENOTSOCK ENOTSOCK
#else
-#define APR_ENOTSOCK (APR_OS_START_SYSERR + 33)
+#define APR_ENOTSOCK (APR_OS_START_ERROR + 133)
#endif
#ifdef ENOTCONN
#define APR_ENOTCONN ENOTCONN
#else
-#define APR_ENOTCONN (APR_OS_START_SYSERR + 34)
+#define APR_ENOTCONN (APR_OS_START_ERROR + 134)
#endif
#ifdef EOPNOTSUPP
#define APR_EOPNOTSUPP EOPNOTSUPP
#else
-#define APR_EOPNOTSUPP (APR_OS_START_SYSERR + 35)
+#define APR_EOPNOTSUPP (APR_OS_START_ERROR + 135)
#endif
#ifdef HOST_NOT_FOUND
#define APR_EHOSTNOTFOUND HOST_NOT_FOUND
#else
-#define APR_EHOSTNOTFOUND (APR_OS_START_SYSERR + 36)
+#define APR_EHOSTNOTFOUND (APR_OS_START_ERROR + 136)
#endif
#ifdef NO_DATA
#define APR_ENODATA NO_DATA
#else
-#define APR_ENODATA (APR_OS_START_SYSERR + 37)
+#define APR_ENODATA (APR_OS_START_ERROR + 137)
#endif
#ifdef NO_ADDRESS
#define APR_ENOADDRESS NO_ADDRESS
#else
-#define APR_ENOADDRESS (APR_OS_START_SYSERR + 38)
+#define APR_ENOADDRESS (APR_OS_START_ERROR + 138)
#endif
#ifdef NO_RECOVERY
#define APR_ENORECOVERY NO_RECOVERY
#else
-#define APR_ENORECOVERY (APR_OS_START_SYSERR + 39)
+#define APR_ENORECOVERY (APR_OS_START_ERROR + 139)
#endif
#ifdef EISCONN
#define APR_EISCONN EISCONN
#else
-#define APR_EISCONN (APR_OS_START_SYSERR + 40)
+#define APR_EISCONN (APR_OS_START_ERROR + 140)
#endif
#ifdef ETIMEDOUT
#define APR_ETIMEDOUT ETIMEDOUT
#else
-#define APR_ETIMEDOUT (APR_OS_START_SYSERR + 41)
+#define APR_ETIMEDOUT (APR_OS_START_ERROR + 141)
#endif
#ifdef ECONNREFUSED
#define APR_ECONNREFUSED ECONNREFUSED
#else
-#define APR_ECONNREFUSED (APR_OS_START_SYSERR + 42)
+#define APR_ECONNREFUSED (APR_OS_START_ERROR + 142)
#endif
#ifdef ENETUNREACH
#define APR_ENETUNREACH ENETUNREACH
#else
-#define APR_ENETUNREACH (APR_OS_START_SYSERR + 43)
+#define APR_ENETUNREACH (APR_OS_START_ERROR + 143)
#endif
#ifdef EADDRINUSE
#define APR_EADDRINUSE EADDRINUSE
#else
-#define APR_EADDRINUSE (APR_OS_START_SYSERR + 44)
+#define APR_EADDRINUSE (APR_OS_START_ERROR + 144)
#endif
#ifdef EINPROGRESS
#define APR_EINPROGRESS EINPROGRESS
#else
-#define APR_EINPROGRESS (APR_OS_START_SYSERR + 45)
+#define APR_EINPROGRESS (APR_OS_START_ERROR + 145)
#endif
#ifdef EALREADY
#define APR_EALREADY EALREADY
#else
-#define APR_EALREADY (APR_OS_START_SYSERR + 46)
+#define APR_EALREADY (APR_OS_START_ERROR + 146)
#endif
#ifdef EAFNOSUPPORT
#define APR_EAFNOSUPPORT EAFNOSUPPORT
#else
-#define APR_EAFNOSUPPORT (APR_OS_START_SYSERR + 47)
+#define APR_EAFNOSUPPORT (APR_OS_START_ERROR + 147)
#endif
#ifdef ENOPROTOOPT
#define APR_ENOPROTOOPT ENOPROTOOPT
#else
-#define APR_ENOPROTOOPT (APR_OS_START_SYSERR + 48)
+#define APR_ENOPROTOOPT (APR_OS_START_ERROR + 148)
#endif
#ifdef ENOCHILD
#define APR_ENOCHILD ENOCHILD
#else
-#define APR_ENOCHILD (APR_OS_START_SYSERR + 49)
+#define APR_ENOCHILD (APR_OS_START_ERROR + 149)
#endif
#ifdef ESRCH
#define APR_ESRCH ESRCH
#else
-#define APR_ESRCH (APR_OS_START_SYSERR + 50)
+#define APR_ESRCH (APR_OS_START_ERROR + 150)
#endif
#ifdef ENOTSUP
#define APR_ENOTSUP ENOTSUP
#else
-#define APR_ENOTSUP (APR_OS_START_SYSERR + 51)
+#define APR_ENOTSUP (APR_OS_START_ERROR + 151)
#endif
#ifdef __cplusplus
--
______________________________________________________________________________
| Brian Havard | "He is not the messiah! |
| brianh@kheldar.apana.org.au | He's a very naughty boy!" - Life of Brian |
------------------------------------------------------------------------------
--
______________________________________________________________________________
| Brian Havard | "He is not the messiah! |
| brianh@kheldar.apana.org.au | He's a very naughty boy!" - Life of Brian |
------------------------------------------------------------------------------