1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/* $Id$
* ============================================================================
*
* = LIBRARY
* pace
*
* = FILENAME
* pace/config/utility.h
*
* = AUTHOR
* Luther Baker
*
* ============================================================================ */
#ifndef PACE_CONFIG_UTILITY_H
#define PACE_CONFIG_UTILITY_H
/* ----------------------------------------------------------------------
* error control
* ---------------------------------------------------------------------- */
#include "pace/errno.h"
int errno;
# define PACE_ERRNO_NO_SUPPORT_RETURN(FAILVALUE) \
return ( (errno = ENOTSUP), FAILVALUE)
# define PACE_ERRNO_NO_SUPPORT() errno=ENOTSUP
/* ----------------------------------------------------------------------
A couple useful inline functions for checking whether bits are
enabled or disabled.
* ---------------------------------------------------------------------- */
# define PACE_POW(X) (((X) == 0)?1:(X-=1,X|=X>>1,X|=X>>2,X|=X>>4,X|=X>>8,X|=X>>16,(++X)))
# define PACE_EVEN(NUM) (((NUM) & 1) == 0)
# define PACE_ODD(NUM) (((NUM) & 1) == 1)
# define PACE_BIT_ENABLED(WORD, BIT) (((WORD) & (BIT)) != 0)
# define PACE_BIT_DISABLED(WORD, BIT) (((WORD) & (BIT)) == 0)
# define PACE_BIT_CMP_MASK(WORD, BIT, MASK) (((WORD) & (BIT)) == MASK)
# define PACE_SET_BITS(WORD, BITS) (WORD |= (BITS))
# define PACE_CLR_BITS(WORD, BITS) (WORD &= ~(BITS))
/* Turn a number into a string. */
# define PACE_ITOA(X) #X
/* Create a string of a server address with a "host:port" format. */
# define PACE_SERVER_ADDRESS(H,P) H":"P
/* ----------------------------------------------------------------------
Specific for (PACE_WIN32)
* ---------------------------------------------------------------------- */
#if (PACE_WIN32)
#include <windows.h>
/* Perform a mapping of Win32 error numbers into POSIX errnos. */
# define PACE_FAIL_RETURN(RESULT) do { \
switch (GetLastError ()) { \
case ERROR_NOT_ENOUGH_MEMORY: errno = ENOMEM; break; \
case ERROR_FILE_EXISTS: errno = EEXIST; break; \
case ERROR_SHARING_VIOLATION: errno = EACCES; break; \
case ERROR_PATH_NOT_FOUND: errno = ENOENT; break; \
} \
return RESULT; } while (0)
/* The "null" device on Win32. */
# define PACE_DEV_NULL "nul"
/* Define the pathname separator characters for Win32 (ugh). */
# define PACE_DIRECTORY_SEPARATOR_STR "\\"
# define PACE_DIRECTORY_SEPARATOR_CHAR '\\'
# define PACE_LD_SEARCH_PATH "PATH"
# define PACE_LD_SEARCH_PATH_SEPARATOR_STR ";"
# define PACE_DLL_SUFFIX ".dll"
# define PACE_DLL_PREFIX ""
# define PACE_SYSCALL_FAILED 0xFFFFFFFF
/* Turns "FALSE" into -1 */
# define PACE_ADAPT_RETVAL(OP,RESULT) \
((RESULT = (OP)) == FALSE ? -1 : 0)
/* If failure, sets errno before returning */
# define PACE_WIN32CALL_RETURN(X,TYPE,FAILVALUE) \
do { \
TYPE pace_result_; \
pace_result_ = (TYPE) X; \
if (pace_result_ == FAILVALUE) \
{ \
errno = GetLastError (); \
} \
return pace_result_; \
} while (0)
/* Casts return value. */
# define PACE_OSCALL_RETURN(X,TYPE,FAILVALUE) \
return (TYPE) X;
#endif /* PACE_WIN32 */
#endif /* PACE_CONFIG_UTILITY_H */
|