00001 00002 // 00003 // Copyright (c) 2000-2003 Intel Corporation 00004 // All rights reserved. 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // * Redistributions of source code must retain the above copyright notice, 00010 // this list of conditions and the following disclaimer. 00011 // * Redistributions in binary form must reproduce the above copyright notice, 00012 // this list of conditions and the following disclaimer in the documentation 00013 // and/or other materials provided with the distribution. 00014 // * Neither name of Intel Corporation nor the names of its contributors 00015 // may be used to endorse or promote products derived from this software 00016 // without specific prior written permission. 00017 // 00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00019 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00020 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 00021 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR 00022 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00025 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00026 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00027 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00028 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00029 // 00031 00032 #ifndef UTIL_H 00033 #define UTIL_H 00034 #include "upnp.h" 00035 00036 // usually used to specify direction of parameters in functions 00037 #ifndef IN 00038 #define IN 00039 #endif 00040 00041 #ifndef OUT 00042 #define OUT 00043 #endif 00044 00045 #ifndef INOUT 00046 #define INOUT 00047 #endif 00048 00049 00050 #ifdef NO_DEBUG 00051 #define DBG(x) 00052 #else 00053 #define DBG(x) x 00054 #endif 00055 00056 #define GEMD_OUT_OF_MEMORY -1 00057 #define EVENT_TIMEDOUT -2 00058 #define EVENT_TERMINATE -3 00059 00060 00061 #ifndef WIN32 00062 #define max(a, b) (((a)>(b))? (a):(b)) 00063 #define min(a, b) (((a)<(b))? (a):(b)) 00064 #endif 00065 00066 00067 // boolean type in C 00068 typedef char xboolean; 00069 00070 #ifndef TRUE 00071 #define TRUE 1 00072 #endif 00073 00074 #ifndef FALSE 00075 #define FALSE 0 00076 #endif 00077 00079 // funcs 00080 00081 #ifdef __cplusplus 00082 extern "C" { 00083 #endif 00084 00085 void log_error( IN const char *fmt, ... ); 00086 00087 /************************************************************************ 00088 * Function : linecopy 00089 * 00090 * Parameters : 00091 * OUT char dest[LINE_SIZE] ; output buffer 00092 * IN const char* src ; input buffer 00093 * 00094 * Description : Copy no of bytes spcified by the LINE_SIZE constant, 00095 * from the source buffer. Null terminate the destination buffer 00096 * 00097 * Return : void ; 00098 * 00099 * Note : 00100 ************************************************************************/ 00101 void linecopy( OUT char dest[LINE_SIZE], IN const char* src ); 00102 00103 /************************************************************************ 00104 * Function : namecopy 00105 * 00106 * Parameters : 00107 * OUT char dest[NAME_SIZE] ; output buffer 00108 * IN const char* src ; input buffer 00109 * 00110 * Description : Copy no of bytes spcified by the NAME_SIZE constant, 00111 * from the source buffer. Null terminate the destination buffer 00112 * 00113 * Return : void ; 00114 * 00115 * Note : 00116 ************************************************************************/ 00117 void namecopy( OUT char dest[NAME_SIZE], IN const char* src ); 00118 00119 /************************************************************************ 00120 * Function : linecopylen 00121 * 00122 * Parameters : 00123 * OUT char dest[LINE_SIZE] ; output buffer 00124 * IN const char* src ; input buffer 00125 * IN size_t srclen ; bytes to be copied. 00126 * 00127 * Description : Determine if the srclen passed in paramter is less than 00128 * the permitted LINE_SIZE. If it is use the passed parameter, if not 00129 * use the permitted LINE_SIZE as the length parameter 00130 * Copy no of bytes spcified by the LINE_SIZE constant, 00131 * from the source buffer. Null terminate the destination buffer 00132 * 00133 * Return : void ; 00134 * 00135 * Note : 00136 ************************************************************************/ 00137 void linecopylen( OUT char dest[LINE_SIZE], IN const char* src, IN size_t srclen ); 00138 00139 00140 #ifdef __cplusplus 00141 } // extern C 00142 #endif 00143 00145 00146 // C specific 00147 #ifndef __cplusplus 00148 00149 #ifndef WIN32 00150 #define XINLINE inline 00151 #else 00152 00153 #ifndef S_ISREG 00154 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) 00155 #endif 00156 00157 #ifndef S_ISDIR 00158 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) 00159 #endif 00160 00161 #define EADDRINUSE WSAEADDRINUSE 00162 00163 #define strcasecmp stricmp 00164 #define strncasecmp strnicmp 00165 00166 #define sleep Sleep 00167 #define usleep(a) Sleep((a)/1000) 00168 #endif 00169 00170 #endif // __cplusplus 00171 00172 #endif /* GENLIB_UTIL_UTIL_H */
1.6.1