2 ****************************************************************************
3 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
5 * Permission to use, copy, modify, and distribute this software and its *
6 * documentation for any purpose and without fee is hereby granted, *
7 * provided that the above copyright notice appear in all copies and *
8 * that both that copyright notice and this permission notice appear in *
9 * supporting documentation, and that the name of IBM not be used in *
10 * advertising or publicity pertaining to distribution of the software *
11 * without specific, written prior permission. *
13 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
15 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
16 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
17 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
18 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
19 ****************************************************************************
21 /* Standard Preamble for .h files
23 Abstract: Contains miscellaneous general-purpose macros.
27 #define MAXSELECT 20 /* Max no. of file desc. to be checked in select() calls */
29 /*------------------------------------------------------------*/
30 #define IN /* Input parameter */
31 #define OUT /* Output parameter */
32 #define INOUT /* Obvious */
33 /*------------------------------------------------------------*/
36 /* Ha, ha!! I did not realize C has a builtin XOR operator! */
37 #define XOR(a,b) (unsigned char) (((a&~b)|(~a&b)) & 0377) /* NOTE: a and b should be unsigned char */
40 /* Conditional debugging output macros */
43 #define say(when, what, how)\
44 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
45 printf how;fflush(stdout);}\
48 #define say(when, what, how) /* null macro; BEWARE: avoid side effects in say() */
51 /* the ones below are obsolete and are here for upward compatibility only */
52 #define say0(when, what, how)\
53 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
54 printf(how);fflush(stdout);}
55 #define say1(when, what, how, x1)\
56 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
57 printf(how, x1); fflush(stdout);}
58 #define say2(when, what, how, x1, x2)\
59 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
60 printf(how, x1, x2); fflush(stdout);}
61 #define say3(when, what, how, x1, x2, x3)\
62 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
63 printf(how, x1, x2, x3); fflush(stdout);}
64 #define say4(when, what, how, x1, x2, x3, x4)\
65 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
66 printf(how, x1, x2, x3, x4); fflush(stdout);}
67 #define say5(when, what, how, x1, x2, x3, x4, x5)\
68 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
69 printf(how, x1, x2, x3, x4, x5); fflush(stdout);}
70 #define say6(when, what, how, x1, x2, x3, x4, x5, x6)\
71 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
72 printf(how, x1, x2, x3, x4, x5, x6); fflush(stdout);}
73 #define say7(when, what, how, x1, x2, x3, x4, x5, x6, x7)\
74 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
75 printf(how, x1, x2, x3, x4, x5, x6, x7); fflush(stdout);}
76 #define say8(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8)\
77 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
78 printf(how, x1, x2, x3, x4, x5, x6, x7, x8); fflush(stdout);}
79 #define say9(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9)\
80 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
81 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9); fflush(stdout);}
82 #define say10(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)\
83 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
84 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); fflush(stdout);}
85 #define say11(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)\
86 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
87 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11); fflush(stdout);}
88 #define say12(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)\
89 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
90 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12); fflush(stdout);}
93 /* length-checked string routines: return 0 on success, -1 on length violation */
94 #define SafeStrCat(dest,src,totalspace)\
95 ((strlen(dest)+strlen(src) < totalspace) ? strcat(dest,src),0 : -1)
97 #define SafeStrCpy(dest,src,totalspace)\
98 ((strlen(src) < totalspace) ? strcpy(dest,src),0 : -1)
101 /* The following definition of assert is slightly modified from the standard 4.2BSD one.
102 This prints out the failing assertion, in addition to the file and line number.
103 BEWARE: avoid quotes in the assertion!!
104 Also beware: you cannot make the NOASSERT case a null macro, because of side effects */
107 #define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);fprintf(stderr, "\t%s\n", # ex); abort();}}
109 #define assert(ex) {if (!(ex)) abort();}
117 #define SystemError(y) (fprintf(stderr, "%d(%s): ", getpid(), LWP_ActiveProcess->name), perror(y))
119 #define SystemError(y) (fprintf(stderr, "%d: ", getpid()), perror(y))