libUPnP  1.8.0
util.h
1 //
3 // Copyright (c) 2000-2003 Intel Corporation
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
14 // * Neither name of Intel Corporation nor the names of its contributors
15 // may be used to endorse or promote products derived from this software
16 // without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
22 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
31 
32 #ifndef UTIL_H
33 #define UTIL_H
34 
35 
36 #include "upnp.h"
37 
38 
39 // usually used to specify direction of parameters in functions
40 #ifndef IN
41  #define IN
42 #endif
43 
44 #ifndef OUT
45  #define OUT
46 #endif
47 
48 #ifndef INOUT
49  #define INOUT
50 #endif
51 
52 
53 #define GEMD_OUT_OF_MEMORY -1
54 #define EVENT_TIMEDOUT -2
55 #define EVENT_TERMINATE -3
56 
57 
58 // boolean type in C
59 typedef char xboolean;
60 
61 #ifndef TRUE
62  #define TRUE 1
63 #endif
64 
65 #ifndef FALSE
66  #define FALSE 0
67 #endif
68 
69 
71 // funcs
72 
73 #ifdef __cplusplus
74 extern "C" {
75 #endif
76 
77 /************************************************************************
78  * Function: logerror
79  *
80  * Parameters:
81  * IN const char *fmt; format string
82  *
83  * Description: Log an error message.
84  *
85  * Return: void
86  ************************************************************************/
87 void log_error( IN const char *fmt, ... );
88 
89 /************************************************************************
90  * Function: linecopy
91  *
92  * Parameters:
93  * OUT char dest[LINE_SIZE]; output buffer
94  * IN const char *src; input buffer
95  *
96  * Description: Copy no of bytes spcified by the LINE_SIZE constant,
97  * from the source buffer. Null terminate the destination buffer.
98  *
99  * Return: void
100  ************************************************************************/
101 void linecopy( OUT char dest[LINE_SIZE], IN const char* src );
102 
103 /************************************************************************
104  * Function: namecopy
105  *
106  * Parameters:
107  * OUT char dest[NAME_SIZE]; output buffer
108  * IN const char *src; input buffer
109  *
110  * Description: Copy no of bytes spcified by the NAME_SIZE constant,
111  * from the source buffer. Null terminate the destination buffer
112  *
113  * Return: void
114  ************************************************************************/
115 void namecopy( OUT char dest[NAME_SIZE], IN const char* src );
116 
117 /************************************************************************
118  * Function: linecopylen
119  *
120  * Parameters:
121  * OUT char dest[LINE_SIZE]; output buffer
122  * IN const char *src; input buffer
123  * IN size_t srclen; bytes to be copied.
124  *
125  * Description : Determine if the srclen passed in paramter is less than
126  * the permitted LINE_SIZE. If it is use the passed parameter, if not
127  * use the permitted LINE_SIZE as the length parameter
128  * Copy no of bytes spcified by the LINE_SIZE constant,
129  * from the source buffer. Null terminate the destination buffer
130  *
131  * Return: void
132  ************************************************************************/
133 void linecopylen( OUT char dest[LINE_SIZE], IN const char* src, IN size_t srclen );
134 
135 
136 #ifdef __cplusplus
137 } // extern C
138 #endif
139 
140 /* Size of the errorBuffer variable, passed to the strerror_r() function */
141 #define ERROR_BUFFER_LEN 256
142 
144 // C specific
145 #ifndef __cplusplus
146 
147 #ifdef WIN32
148  #ifndef S_ISREG
149  #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
150  #endif
151 
152  #ifndef S_ISDIR
153  #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
154  #endif
155 
156  #define EADDRINUSE WSAEADDRINUSE
157 
158  #define strcasecmp stricmp
159  #define strncasecmp strnicmp
160 
161  #define sleep(a) Sleep((a)*1000)
162  #define usleep(a) Sleep((a)/1000)
163 
164  #define strerror_r(a,b,c) (strerror_s((b),(c),(a)))
165 #else
166  #define max(a, b) (((a)>(b))? (a):(b))
167  #define min(a, b) (((a)<(b))? (a):(b))
168 #endif /* WIN32 */
169 
170 #endif // __cplusplus
171 
172 #endif /* UTIL_H */
173