util.h

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 
00035 
00036 #include "upnp.h"
00037 
00038 
00039 // usually used to specify direction of parameters in functions
00040 #ifndef IN
00041         #define IN
00042 #endif
00043 
00044 #ifndef OUT
00045         #define OUT
00046 #endif
00047 
00048 #ifndef INOUT
00049         #define INOUT
00050 #endif
00051 
00052 
00053 #define GEMD_OUT_OF_MEMORY -1
00054 #define EVENT_TIMEDOUT -2
00055 #define EVENT_TERMINATE -3
00056 
00057 
00058 // boolean type in C
00059 typedef char xboolean;
00060 
00061 #ifndef TRUE
00062         #define TRUE 1
00063 #endif
00064 
00065 #ifndef FALSE
00066         #define FALSE 0
00067 #endif
00068 
00069 
00071 // funcs
00072 
00073 #ifdef __cplusplus
00074 extern "C" {
00075 #endif
00076 
00077 /************************************************************************
00078  * Function: logerror
00079  *
00080  * Parameters:
00081  *      IN const char *fmt;     format string
00082  *
00083  * Description: Log an error message.
00084  *
00085  * Return: void
00086  ************************************************************************/
00087 void log_error( IN const char *fmt, ... );
00088 
00089 /************************************************************************
00090  * Function: linecopy
00091  *
00092  * Parameters:
00093  *      OUT char dest[LINE_SIZE];       output buffer
00094  *      IN const char *src;             input buffer
00095  *
00096  * Description: Copy no of bytes spcified by the LINE_SIZE constant, 
00097  *      from the source buffer. Null terminate the destination buffer.
00098  *
00099  * Return: void
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 void namecopy( OUT char dest[NAME_SIZE], IN const char* src );
00116 
00117 /************************************************************************
00118  * Function:    linecopylen
00119  *
00120  * Parameters:
00121  *      OUT char dest[LINE_SIZE];       output buffer
00122  *      IN const char *src;             input buffer
00123  *      IN size_t srclen;               bytes to be copied.
00124  *
00125  * Description : Determine if the srclen passed in paramter is less than 
00126  *      the permitted LINE_SIZE. If it is use the passed parameter, if not
00127  *      use the permitted LINE_SIZE as the length parameter
00128  *      Copy no of bytes spcified by the LINE_SIZE constant, 
00129  *      from the source buffer. Null terminate the destination buffer
00130  *
00131  * Return: void
00132  ************************************************************************/
00133 void linecopylen( OUT char dest[LINE_SIZE], IN const char* src, IN size_t srclen );
00134 
00135 
00136 #ifdef __cplusplus
00137 } // extern C
00138 #endif
00139 
00140 /* Size of the errorBuffer variable, passed to the strerror_r() function */
00141 #define ERROR_BUFFER_LEN 256
00142 
00144 // C specific
00145 #ifndef __cplusplus
00146 
00147 #ifdef WIN32
00148         #ifndef S_ISREG
00149                 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
00150         #endif
00151 
00152         #ifndef S_ISDIR
00153                 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
00154         #endif
00155 
00156         #define EADDRINUSE              WSAEADDRINUSE
00157 
00158         #define strcasecmp              stricmp
00159         #define strncasecmp             strnicmp
00160 
00161         #define sleep(a)                Sleep((a)*1000)
00162         #define usleep(a)               Sleep((a)/1000)
00163 
00164         #define strerror_r(a,b,c)       (strerror_s((b),(c),(a)))
00165 #else
00166         #define max(a, b)   (((a)>(b))? (a):(b))
00167         #define min(a, b)   (((a)<(b))? (a):(b))
00168 #endif /* WIN32 */
00169 
00170 #endif // __cplusplus
00171 
00172 #endif /* UTIL_H */
00173