2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
10 /* Standard Preamble for .h files
12 Abstract: Contains miscellaneous general-purpose macros.
16 #define MAXSELECT 20 /* Max no. of file desc. to be checked in select() calls */
18 /*------------------------------------------------------------*/
19 #define IN /* Input parameter */
20 #define OUT /* Output parameter */
21 #define INOUT /* Obvious */
22 /*------------------------------------------------------------*/
25 /* Ha, ha!! I did not realize C has a builtin XOR operator! */
26 #define XOR(a,b) (unsigned char) (((a&~b)|(~a&b)) & 0377) /* NOTE: a and b should be unsigned char */
29 /* Conditional debugging output macros */
32 #define say(when, what, how)\
33 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
34 printf how;fflush(stdout);}\
37 #define say(when, what, how) /* null macro; BEWARE: avoid side effects in say() */
40 /* the ones below are obsolete and are here for upward compatibility only */
41 #define say0(when, what, how)\
42 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
43 printf(how);fflush(stdout);}
44 #define say1(when, what, how, x1)\
45 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
46 printf(how, x1); fflush(stdout);}
47 #define say2(when, what, how, x1, x2)\
48 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
49 printf(how, x1, x2); fflush(stdout);}
50 #define say3(when, what, how, x1, x2, x3)\
51 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
52 printf(how, x1, x2, x3); fflush(stdout);}
53 #define say4(when, what, how, x1, x2, x3, x4)\
54 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
55 printf(how, x1, x2, x3, x4); fflush(stdout);}
56 #define say5(when, what, how, x1, x2, x3, x4, x5)\
57 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
58 printf(how, x1, x2, x3, x4, x5); fflush(stdout);}
59 #define say6(when, what, how, x1, x2, x3, x4, x5, x6)\
60 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
61 printf(how, x1, x2, x3, x4, x5, x6); fflush(stdout);}
62 #define say7(when, what, how, x1, x2, x3, x4, x5, x6, x7)\
63 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
64 printf(how, x1, x2, x3, x4, x5, x6, x7); fflush(stdout);}
65 #define say8(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8)\
66 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
67 printf(how, x1, x2, x3, x4, x5, x6, x7, x8); fflush(stdout);}
68 #define say9(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9)\
69 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
70 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9); fflush(stdout);}
71 #define say10(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10)\
72 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
73 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10); fflush(stdout);}
74 #define say11(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11)\
75 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
76 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11); fflush(stdout);}
77 #define say12(when, what, how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12)\
78 if (when < what){printf("\"%s\", line %d: ", __FILE__, __LINE__);\
79 printf(how, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12); fflush(stdout);}
82 /* length-checked string routines: return 0 on success, -1 on length violation */
83 #define SafeStrCat(dest,src,totalspace)\
84 ((strlen(dest)+strlen(src) < totalspace) ? strcat(dest,src),0 : -1)
86 #define SafeStrCpy(dest,src,totalspace)\
87 ((strlen(src) < totalspace) ? strcpy(dest,src),0 : -1)
90 /* The following definition of assert is slightly modified from the standard 4.2BSD one.
91 This prints out the failing assertion, in addition to the file and line number.
92 BEWARE: avoid quotes in the assertion!!
93 Also beware: you cannot make the NOASSERT case a null macro, because of side effects */
97 #define assert(ex) {if (!(ex)){fprintf(stderr,"Assertion failed: file %s, line %d\n", __FILE__, __LINE__);fprintf(stderr, "\t%s\n", # ex); abort();}}
99 #define assert(ex) {if (!(ex)) abort();}
107 #define SystemError(y) (fprintf(stderr, "%d(%s): ", getpid(), LWP_ActiveProcess->name), perror(y))
109 #define SystemError(y) (fprintf(stderr, "%d: ", getpid()), perror(y))