diff options
author | Nils Durner <durner@gnunet.org> | 2009-06-10 22:24:54 +0000 |
---|---|---|
committer | Nils Durner <durner@gnunet.org> | 2009-06-10 22:24:54 +0000 |
commit | 9cf5b99404c1f3694417b2e4900771398022fd23 (patch) | |
tree | e6e8f99d21a6ae94894c774b7505b95ae370ccff /src | |
parent | 812138f1d6cbd39d2ec623f2201bb034ab4ac3d2 (diff) | |
download | gnunet-9cf5b99404c1f3694417b2e4900771398022fd23.tar.gz gnunet-9cf5b99404c1f3694417b2e4900771398022fd23.zip |
MinGW
Diffstat (limited to 'src')
-rw-r--r-- | src/include/plibc.h | 1026 | ||||
-rw-r--r-- | src/util/Makefile.am | 4 | ||||
-rw-r--r-- | src/util/crypto_rsa.c | 16 | ||||
-rw-r--r-- | src/util/disk.c | 2 | ||||
-rw-r--r-- | src/util/network.c | 36 | ||||
-rw-r--r-- | src/util/os_priority.c | 81 | ||||
-rw-r--r-- | src/util/scheduler.c | 2 | ||||
-rw-r--r-- | src/util/server.c | 3 | ||||
-rw-r--r-- | src/util/time.c | 2 | ||||
-rw-r--r-- | src/util/win.cc | 828 | ||||
-rw-r--r-- | src/util/winproc.c | 254 |
11 files changed, 1831 insertions, 423 deletions
diff --git a/src/include/plibc.h b/src/include/plibc.h index 93ca012e1..51d78fc7e 100644 --- a/src/include/plibc.h +++ b/src/include/plibc.h | |||
@@ -1,17 +1,17 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of PlibC. | 2 | This file is part of PlibC. |
3 | (C) 2005, 2006, 2007, 2008 Nils Durner (and other contributing authors) | 3 | (C) 2005, 2006, 2007, 2008, 2009 Nils Durner (and other contributing authors) |
4 | 4 | ||
5 | This library is free software; you can redistribute it and/or | 5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Lesser General Public | 6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | 7 | License as published by the Free Software Foundation; either |
8 | version 2.1 of the License, or (at your option) any later version. | 8 | version 2.1 of the License, or (at your option) any later version. |
9 | 9 | ||
10 | This library is distributed in the hope that it will be useful, | 10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Lesser General Public License for more details. | 13 | Lesser General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Lesser General Public | 15 | You should have received a copy of the GNU Lesser General Public |
16 | License along with this library; if not, write to the Free Software | 16 | License along with this library; if not, write to the Free Software |
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
@@ -22,33 +22,33 @@ | |||
22 | * @brief PlibC header | 22 | * @brief PlibC header |
23 | * @attention This file is usually not installed under Unix, | 23 | * @attention This file is usually not installed under Unix, |
24 | * so ship it with your application | 24 | * so ship it with your application |
25 | * @version $Revision: 1.46 $ | 25 | * @version $Revision: 39 $ |
26 | */ | 26 | */ |
27 | 27 | ||
28 | #ifndef _PLIBC_H_ | 28 | #ifndef _PLIBC_H_ |
29 | #define _PLIBC_H_ | 29 | #define _PLIBC_H_ |
30 | 30 | ||
31 | #ifndef SIGALRM | 31 | #ifndef SIGALRM |
32 | #define SIGALRM 14 | 32 | #define SIGALRM 14 |
33 | #endif /* */ | 33 | #endif |
34 | 34 | ||
35 | #ifdef __cplusplus | 35 | #ifdef __cplusplus |
36 | extern "C" | 36 | extern "C" { |
37 | { | 37 | #endif |
38 | 38 | ||
39 | #endif /* */ | 39 | #include <stddef.h> |
40 | 40 | ||
41 | #ifdef Q_OS_WIN32 | 41 | #ifdef Q_OS_WIN32 |
42 | #define WINDOWS 1 | 42 | #define WINDOWS 1 |
43 | #endif /* */ | 43 | #endif |
44 | 44 | ||
45 | #define HAVE_PLIBC_FD 0 | 45 | #define HAVE_PLIBC_FD 0 |
46 | 46 | ||
47 | #ifdef WINDOWS | 47 | #ifdef WINDOWS |
48 | 48 | ||
49 | #if ENABLE_NLS | 49 | #if ENABLE_NLS |
50 | #include "langinfo.h" | 50 | #include "langinfo.h" |
51 | #endif /* */ | 51 | #endif |
52 | 52 | ||
53 | #include <windows.h> | 53 | #include <windows.h> |
54 | #include <Ws2tcpip.h> | 54 | #include <Ws2tcpip.h> |
@@ -68,14 +68,16 @@ extern "C" | |||
68 | 68 | ||
69 | /* Convert LARGE_INTEGER to double */ | 69 | /* Convert LARGE_INTEGER to double */ |
70 | #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ | 70 | #define Li2Double(x) ((double)((x).HighPart) * 4.294967296E9 + \ |
71 | (double) ((x).LowPart)) | 71 | (double)((x).LowPart)) |
72 | |||
72 | #define socklen_t int | 73 | #define socklen_t int |
73 | #define ssize_t int | 74 | #define ssize_t int |
74 | #define off_t int | 75 | #define off_t int |
75 | #define int64_t long long | 76 | #define int64_t long long |
76 | #define int32_t long | 77 | #define int32_t long |
77 | struct stat64 | 78 | |
78 | { | 79 | struct stat64 |
80 | { | ||
79 | _dev_t st_dev; | 81 | _dev_t st_dev; |
80 | _ino_t st_ino; | 82 | _ino_t st_ino; |
81 | _mode_t st_mode; | 83 | _mode_t st_mode; |
@@ -87,112 +89,116 @@ extern "C" | |||
87 | __time64_t st_atime; | 89 | __time64_t st_atime; |
88 | __time64_t st_mtime; | 90 | __time64_t st_mtime; |
89 | __time64_t st_ctime; | 91 | __time64_t st_ctime; |
90 | }; | 92 | }; |
91 | 93 | ||
92 | #ifndef pid_t | 94 | #ifndef pid_t |
93 | #define pid_t int | 95 | #define pid_t int |
94 | #endif /* */ | 96 | #endif |
95 | 97 | ||
96 | #ifndef WEXITSTATUS | 98 | #ifndef WEXITSTATUS |
97 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) | 99 | #define WEXITSTATUS(status) (((status) & 0xff00) >> 8) |
98 | #endif /* */ | 100 | #endif |
101 | |||
102 | #ifndef MSG_DONTWAIT | ||
103 | #define MSG_DONTWAIT 0 | ||
104 | #endif | ||
99 | 105 | ||
100 | /* Thanks to the Cygwin project */ | 106 | /* Thanks to the Cygwin project */ |
101 | #define ENOCSI 43 /* No CSI structure available */ | 107 | #define ENOCSI 43 /* No CSI structure available */ |
102 | #define EL2HLT 44 /* Level 2 halted */ | 108 | #define EL2HLT 44 /* Level 2 halted */ |
103 | #ifndef EDEADLK | 109 | #ifndef EDEADLK |
104 | #define EDEADLK 45 /* Deadlock condition */ | 110 | #define EDEADLK 45 /* Deadlock condition */ |
105 | #endif /* */ | 111 | #endif |
106 | #ifndef ENOLCK | 112 | #ifndef ENOLCK |
107 | #define ENOLCK 46 /* No record locks available */ | 113 | #define ENOLCK 46 /* No record locks available */ |
108 | #endif /* */ | 114 | #endif |
109 | #define EBADE 50 /* Invalid exchange */ | 115 | #define EBADE 50 /* Invalid exchange */ |
110 | #define EBADR 51 /* Invalid request descriptor */ | 116 | #define EBADR 51 /* Invalid request descriptor */ |
111 | #define EXFULL 52 /* Exchange full */ | 117 | #define EXFULL 52 /* Exchange full */ |
112 | #define ENOANO 53 /* No anode */ | 118 | #define ENOANO 53 /* No anode */ |
113 | #define EBADRQC 54 /* Invalid request code */ | 119 | #define EBADRQC 54 /* Invalid request code */ |
114 | #define EBADSLT 55 /* Invalid slot */ | 120 | #define EBADSLT 55 /* Invalid slot */ |
115 | #ifndef EDEADLOCK | 121 | #ifndef EDEADLOCK |
116 | #define EDEADLOCK EDEADLK /* File locking deadlock error */ | 122 | #define EDEADLOCK EDEADLK /* File locking deadlock error */ |
117 | #endif /* */ | 123 | #endif |
118 | #define EBFONT 57 /* Bad font file fmt */ | 124 | #define EBFONT 57 /* Bad font file fmt */ |
119 | #define ENOSTR 60 /* Device not a stream */ | 125 | #define ENOSTR 60 /* Device not a stream */ |
120 | #define ENODATA 61 /* No data (for no delay io) */ | 126 | #define ENODATA 61 /* No data (for no delay io) */ |
121 | #define ETIME 62 /* Timer expired */ | 127 | #define ETIME 62 /* Timer expired */ |
122 | #define ENOSR 63 /* Out of streams resources */ | 128 | #define ENOSR 63 /* Out of streams resources */ |
123 | #define ENONET 64 /* Machine is not on the network */ | 129 | #define ENONET 64 /* Machine is not on the network */ |
124 | #define ENOPKG 65 /* Package not installed */ | 130 | #define ENOPKG 65 /* Package not installed */ |
125 | #define EREMOTE 66 /* The object is remote */ | 131 | #define EREMOTE 66 /* The object is remote */ |
126 | #define ENOLINK 67 /* The link has been severed */ | 132 | #define ENOLINK 67 /* The link has been severed */ |
127 | #define EADV 68 /* Advertise error */ | 133 | #define EADV 68 /* Advertise error */ |
128 | #define ESRMNT 69 /* Srmount error */ | 134 | #define ESRMNT 69 /* Srmount error */ |
129 | #define ECOMM 70 /* Communication error on send */ | 135 | #define ECOMM 70 /* Communication error on send */ |
130 | #define EPROTO 71 /* Protocol error */ | 136 | #define EPROTO 71 /* Protocol error */ |
131 | #define EMULTIHOP 74 /* Multihop attempted */ | 137 | #define EMULTIHOP 74 /* Multihop attempted */ |
132 | #define ELBIN 75 /* Inode is remote (not really error) */ | 138 | #define ELBIN 75 /* Inode is remote (not really error) */ |
133 | #define EDOTDOT 76 /* Cross mount point (not really error) */ | 139 | #define EDOTDOT 76 /* Cross mount point (not really error) */ |
134 | #define EBADMSG 77 /* Trying to read unreadable message */ | 140 | #define EBADMSG 77 /* Trying to read unreadable message */ |
135 | #define ENOTUNIQ 80 /* Given log. name not unique */ | 141 | #define ENOTUNIQ 80 /* Given log. name not unique */ |
136 | #define EBADFD 81 /* f.d. invalid for this operation */ | 142 | #define EBADFD 81 /* f.d. invalid for this operation */ |
137 | #define EREMCHG 82 /* Remote address changed */ | 143 | #define EREMCHG 82 /* Remote address changed */ |
138 | #define ELIBACC 83 /* Can't access a needed shared lib */ | 144 | #define ELIBACC 83 /* Can't access a needed shared lib */ |
139 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ | 145 | #define ELIBBAD 84 /* Accessing a corrupted shared lib */ |
140 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ | 146 | #define ELIBSCN 85 /* .lib section in a.out corrupted */ |
141 | #define ELIBMAX 86 /* Attempting to link in too many libs */ | 147 | #define ELIBMAX 86 /* Attempting to link in too many libs */ |
142 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ | 148 | #define ELIBEXEC 87 /* Attempting to exec a shared library */ |
143 | #ifndef ENOSYS | 149 | #ifndef ENOSYS |
144 | #define ENOSYS 88 /* Function not implemented */ | 150 | #define ENOSYS 88 /* Function not implemented */ |
145 | #endif /* */ | 151 | #endif |
146 | #define ENMFILE 89 /* No more files */ | 152 | #define ENMFILE 89 /* No more files */ |
147 | #ifndef ENOTEMPTY | 153 | #ifndef ENOTEMPTY |
148 | #define ENOTEMPTY 90 /* Directory not empty */ | 154 | #define ENOTEMPTY 90 /* Directory not empty */ |
149 | #endif /* */ | 155 | #endif |
150 | #ifndef ENAMETOOLONG | 156 | #ifndef ENAMETOOLONG |
151 | #define ENAMETOOLONG 91 /* File or path name too long */ | 157 | #define ENAMETOOLONG 91 /* File or path name too long */ |
152 | #endif /* */ | 158 | #endif |
153 | #define ELOOP 92 /* Too many symbolic links */ | 159 | #define ELOOP 92 /* Too many symbolic links */ |
154 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ | 160 | #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ |
155 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ | 161 | #define EPFNOSUPPORT 96 /* Protocol family not supported */ |
156 | #define ECONNRESET 104 /* Connection reset by peer */ | 162 | #define ECONNRESET 104 /* Connection reset by peer */ |
157 | #define ENOBUFS 105 /* No buffer space available */ | 163 | #define ENOBUFS 105 /* No buffer space available */ |
158 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ | 164 | #define EAFNOSUPPORT 106 /* Address family not supported by protocol family */ |
159 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ | 165 | #define EPROTOTYPE 107 /* Protocol wrong type for socket */ |
160 | #define ENOTSOCK 108 /* Socket operation on non-socket */ | 166 | #define ENOTSOCK 108 /* Socket operation on non-socket */ |
161 | #define ENOPROTOOPT 109 /* Protocol not available */ | 167 | #define ENOPROTOOPT 109 /* Protocol not available */ |
162 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ | 168 | #define ESHUTDOWN 110 /* Can't send after socket shutdown */ |
163 | #define ECONNREFUSED 111 /* Connection refused */ | 169 | #define ECONNREFUSED 111 /* Connection refused */ |
164 | #define EADDRINUSE 112 /* Address already in use */ | 170 | #define EADDRINUSE 112 /* Address already in use */ |
165 | #define ECONNABORTED 113 /* Connection aborted */ | 171 | #define ECONNABORTED 113 /* Connection aborted */ |
166 | #define ENETUNREACH 114 /* Network is unreachable */ | 172 | #define ENETUNREACH 114 /* Network is unreachable */ |
167 | #define ENETDOWN 115 /* Network interface is not configured */ | 173 | #define ENETDOWN 115 /* Network interface is not configured */ |
168 | #ifndef ETIMEDOUT | 174 | #ifndef ETIMEDOUT |
169 | #define ETIMEDOUT 116 /* Connection timed out */ | 175 | #define ETIMEDOUT 116 /* Connection timed out */ |
170 | #endif /* */ | 176 | #endif |
171 | #define EHOSTDOWN 117 /* Host is down */ | 177 | #define EHOSTDOWN 117 /* Host is down */ |
172 | #define EHOSTUNREACH 118 /* Host is unreachable */ | 178 | #define EHOSTUNREACH 118 /* Host is unreachable */ |
173 | #define EINPROGRESS 119 /* Connection already in progress */ | 179 | #define EINPROGRESS 119 /* Connection already in progress */ |
174 | #define EALREADY 120 /* Socket already connected */ | 180 | #define EALREADY 120 /* Socket already connected */ |
175 | #define EDESTADDRREQ 121 /* Destination address required */ | 181 | #define EDESTADDRREQ 121 /* Destination address required */ |
176 | #define EMSGSIZE 122 /* Message too long */ | 182 | #define EMSGSIZE 122 /* Message too long */ |
177 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ | 183 | #define EPROTONOSUPPORT 123 /* Unknown protocol */ |
178 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ | 184 | #define ESOCKTNOSUPPORT 124 /* Socket type not supported */ |
179 | #define EADDRNOTAVAIL 125 /* Address not available */ | 185 | #define EADDRNOTAVAIL 125 /* Address not available */ |
180 | #define ENETRESET 126 /* Connection aborted by network */ | 186 | #define ENETRESET 126 /* Connection aborted by network */ |
181 | #define EISCONN 127 /* Socket is already connected */ | 187 | #define EISCONN 127 /* Socket is already connected */ |
182 | #define ENOTCONN 128 /* Socket is not connected */ | 188 | #define ENOTCONN 128 /* Socket is not connected */ |
183 | #define ETOOMANYREFS 129 /* Too many references: cannot splice */ | 189 | #define ETOOMANYREFS 129 /* Too many references: cannot splice */ |
184 | #define EPROCLIM 130 /* Too many processes */ | 190 | #define EPROCLIM 130 /* Too many processes */ |
185 | #define EUSERS 131 /* Too many users */ | 191 | #define EUSERS 131 /* Too many users */ |
186 | #define EDQUOT 132 /* Disk quota exceeded */ | 192 | #define EDQUOT 132 /* Disk quota exceeded */ |
187 | #define ESTALE 133 /* Unknown error */ | 193 | #define ESTALE 133 /* Unknown error */ |
188 | #ifndef ENOTSUP | 194 | #ifndef ENOTSUP |
189 | #define ENOTSUP 134 /* Not supported */ | 195 | #define ENOTSUP 134 /* Not supported */ |
190 | #endif /* */ | 196 | #endif |
191 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ | 197 | #define ENOMEDIUM 135 /* No medium (in tape drive) */ |
192 | #define ENOSHARE 136 /* No such host or network path */ | 198 | #define ENOSHARE 136 /* No such host or network path */ |
193 | #define ECASECLASH 137 /* Filename exists with different case */ | 199 | #define ECASECLASH 137 /* Filename exists with different case */ |
194 | #define EWOULDBLOCK EAGAIN /* Operation would block */ | 200 | #define EWOULDBLOCK EAGAIN /* Operation would block */ |
195 | #define EOVERFLOW 139 /* Value too large for defined data type */ | 201 | #define EOVERFLOW 139 /* Value too large for defined data type */ |
196 | 202 | ||
197 | #undef HOST_NOT_FOUND | 203 | #undef HOST_NOT_FOUND |
198 | #define HOST_NOT_FOUND 1 | 204 | #define HOST_NOT_FOUND 1 |
@@ -206,46 +212,68 @@ extern "C" | |||
206 | #define PROT_READ 0x1 | 212 | #define PROT_READ 0x1 |
207 | #define PROT_WRITE 0x2 | 213 | #define PROT_WRITE 0x2 |
208 | #define MAP_SHARED 0x1 | 214 | #define MAP_SHARED 0x1 |
209 | #define MAP_PRIVATE 0x2 /* unsupported */ | 215 | #define MAP_PRIVATE 0x2 /* unsupported */ |
210 | #define MAP_FIXED 0x10 | 216 | #define MAP_FIXED 0x10 |
211 | #define MAP_FAILED ((void *)-1) | 217 | #define MAP_FAILED ((void *)-1) |
212 | struct statfs | 218 | |
213 | { | 219 | struct statfs |
214 | long f_type; /* type of filesystem (see below) */ | 220 | { |
215 | long f_bsize; /* optimal transfer block size */ | 221 | long f_type; /* type of filesystem (see below) */ |
216 | long f_blocks; /* total data blocks in file system */ | 222 | long f_bsize; /* optimal transfer block size */ |
217 | long f_bfree; /* free blocks in fs */ | 223 | long f_blocks; /* total data blocks in file system */ |
218 | long f_bavail; /* free blocks avail to non-superuser */ | 224 | long f_bfree; /* free blocks in fs */ |
219 | long f_files; /* total file nodes in file system */ | 225 | long f_bavail; /* free blocks avail to non-superuser */ |
220 | long f_ffree; /* free file nodes in fs */ | 226 | long f_files; /* total file nodes in file system */ |
221 | long f_fsid; /* file system id */ | 227 | long f_ffree; /* free file nodes in fs */ |
222 | long f_namelen; /* maximum length of filenames */ | 228 | long f_fsid; /* file system id */ |
223 | long f_spare[6]; /* spare for later */ | 229 | long f_namelen; /* maximum length of filenames */ |
224 | }; | 230 | long f_spare[6]; /* spare for later */ |
225 | extern const struct in6_addr in6addr_any; /* :: */ | 231 | }; |
226 | extern const struct in6_addr in6addr_loopback; /* ::1 */ | 232 | |
233 | extern const struct in6_addr in6addr_any; /* :: */ | ||
234 | extern const struct in6_addr in6addr_loopback; /* ::1 */ | ||
227 | 235 | ||
228 | /* Taken from the Wine project <http://www.winehq.org> | 236 | /* Taken from the Wine project <http://www.winehq.org> |
229 | /wine/include/winternl.h */ | 237 | /wine/include/winternl.h */ |
230 | enum SYSTEM_INFORMATION_CLASS | 238 | enum SYSTEM_INFORMATION_CLASS |
231 | { SystemBasicInformation = 0, Unknown1, SystemPerformanceInformation = 2, SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ | 239 | { |
232 | Unknown4, SystemProcessInformation = | 240 | SystemBasicInformation = 0, |
233 | 5, Unknown6, Unknown7, SystemProcessorPerformanceInformation = | 241 | Unknown1, |
234 | 8, Unknown9, Unknown10, SystemDriverInformation, Unknown12, | 242 | SystemPerformanceInformation = 2, |
235 | Unknown13, Unknown14, Unknown15, SystemHandleList, Unknown17, | 243 | SystemTimeOfDayInformation = 3, /* was SystemTimeInformation */ |
236 | Unknown18, Unknown19, Unknown20, SystemCacheInformation, | 244 | Unknown4, |
237 | Unknown22, SystemInterruptInformation = | 245 | SystemProcessInformation = 5, |
238 | 23, SystemExceptionInformation = | 246 | Unknown6, |
239 | 33, SystemRegistryQuotaInformation = 37, SystemLookasideInformation = 45 | 247 | Unknown7, |
240 | }; | 248 | SystemProcessorPerformanceInformation = 8, |
241 | typedef struct | 249 | Unknown9, |
242 | { | 250 | Unknown10, |
251 | SystemDriverInformation, | ||
252 | Unknown12, | ||
253 | Unknown13, | ||
254 | Unknown14, | ||
255 | Unknown15, | ||
256 | SystemHandleList, | ||
257 | Unknown17, | ||
258 | Unknown18, | ||
259 | Unknown19, | ||
260 | Unknown20, | ||
261 | SystemCacheInformation, | ||
262 | Unknown22, | ||
263 | SystemInterruptInformation = 23, | ||
264 | SystemExceptionInformation = 33, | ||
265 | SystemRegistryQuotaInformation = 37, | ||
266 | SystemLookasideInformation = 45 | ||
267 | }; | ||
268 | |||
269 | typedef struct | ||
270 | { | ||
243 | LARGE_INTEGER IdleTime; | 271 | LARGE_INTEGER IdleTime; |
244 | LARGE_INTEGER KernelTime; | 272 | LARGE_INTEGER KernelTime; |
245 | LARGE_INTEGER UserTime; | 273 | LARGE_INTEGER UserTime; |
246 | LARGE_INTEGER Reserved1[2]; | 274 | LARGE_INTEGER Reserved1[2]; |
247 | ULONG Reserved2; | 275 | ULONG Reserved2; |
248 | } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; | 276 | } SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION; |
249 | 277 | ||
250 | #define sleep(secs) (Sleep(secs * 1000)) | 278 | #define sleep(secs) (Sleep(secs * 1000)) |
251 | 279 | ||
@@ -262,11 +290,11 @@ extern "C" | |||
262 | #define SHUT_RDWR SD_BOTH | 290 | #define SHUT_RDWR SD_BOTH |
263 | 291 | ||
264 | /* Operations for flock() */ | 292 | /* Operations for flock() */ |
265 | #define LOCK_SH 1 /* shared lock */ | 293 | #define LOCK_SH 1 /* shared lock */ |
266 | #define LOCK_EX 2 /* exclusive lock */ | 294 | #define LOCK_EX 2 /* exclusive lock */ |
267 | #define LOCK_NB 4 /* or'd with one of the above to prevent | 295 | #define LOCK_NB 4 /* or'd with one of the above to prevent |
268 | blocking */ | 296 | blocking */ |
269 | #define LOCK_UN 8 /* remove lock */ | 297 | #define LOCK_UN 8 /* remove lock */ |
270 | 298 | ||
271 | /* Not supported under MinGW */ | 299 | /* Not supported under MinGW */ |
272 | #define S_IRGRP 0 | 300 | #define S_IRGRP 0 |
@@ -289,294 +317,468 @@ extern "C" | |||
289 | #define SIGTERM 15 | 317 | #define SIGTERM 15 |
290 | 318 | ||
291 | #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) | 319 | #define SetErrnoFromWinError(e) _SetErrnoFromWinError(e, __FILE__, __LINE__) |
292 | BOOL _plibc_CreateShortcut (const char *pszSrc, const char *pszDest); | ||
293 | BOOL _plibc_DereferenceShortcut (char *pszShortcut); | ||
294 | char *plibc_ChooseDir (char *pszTitle, unsigned long ulFlags); | ||
295 | char *plibc_ChooseFile (char *pszTitle, unsigned long ulFlags); | ||
296 | long QueryRegistry (HKEY hMainKey, char *pszKey, char *pszSubKey, | ||
297 | char *pszBuffer, long *pdLength); | ||
298 | BOOL __win_IsHandleMarkedAsBlocking (SOCKET hHandle); | ||
299 | void __win_SetHandleBlockingMode (SOCKET s, BOOL bBlocking); | ||
300 | void __win_DiscardHandleBlockingMode (SOCKET s); | ||
301 | int _win_isSocketValid (int s); | ||
302 | int plibc_conv_to_win_path (const char *pszUnix, char *pszWindows); | ||
303 | unsigned plibc_get_handle_count (); | ||
304 | typedef void (*TPanicProc) (int, char *); | ||
305 | void plibc_set_panic_proc (TPanicProc proc); | ||
306 | int flock (int fd, int operation); | ||
307 | int fsync (int fildes); | ||
308 | int inet_pton (int af, const char *src, void *dst); | ||
309 | int inet_pton4 (const char *src, u_char * dst, int pton); | ||
310 | 320 | ||
321 | BOOL _plibc_CreateShortcut(const char *pszSrc, const char *pszDest); | ||
322 | BOOL _plibc_DereferenceShortcut(char *pszShortcut); | ||
323 | char *plibc_ChooseDir(char *pszTitle, unsigned long ulFlags); | ||
324 | char *plibc_ChooseFile(char *pszTitle, unsigned long ulFlags); | ||
325 | long QueryRegistry(HKEY hMainKey, char *pszKey, char *pszSubKey, | ||
326 | char *pszBuffer, long *pdLength); | ||
327 | |||
328 | BOOL __win_IsHandleMarkedAsBlocking(SOCKET hHandle); | ||
329 | void __win_SetHandleBlockingMode(SOCKET s, BOOL bBlocking); | ||
330 | void __win_DiscardHandleBlockingMode(SOCKET s); | ||
331 | int _win_isSocketValid(int s); | ||
332 | int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows); | ||
333 | unsigned plibc_get_handle_count(); | ||
334 | |||
335 | typedef void (*TPanicProc) (int, char *); | ||
336 | void plibc_set_panic_proc(TPanicProc proc); | ||
337 | |||
338 | int flock(int fd, int operation); | ||
339 | int fsync(int fildes); | ||
340 | int inet_pton(int af, const char *src, void *dst); | ||
341 | int inet_pton4(const char *src, u_char *dst, int pton); | ||
311 | #if USE_IPV6 | 342 | #if USE_IPV6 |
312 | int inet_pton6 (const char *src, u_char * dst); | 343 | int inet_pton6(const char *src, u_char *dst); |
313 | 344 | #endif | |
314 | #endif /* */ | 345 | int truncate(const char *fname, int distance); |
315 | int truncate (const char *fname, int distance); | 346 | int statfs(const char *path, struct statfs *buf); |
316 | int statfs (const char *path, struct statfs *buf); | 347 | const char *hstrerror(int err); |
317 | const char *hstrerror (int err); | 348 | int mkstemp(char *tmplate); |
318 | void gettimeofday (struct timeval *tp, void *tzp); | 349 | char *strptime (const char *buf, const char *format, struct tm *tm); |
319 | int mkstemp (char *tmplate); | 350 | const char *inet_ntop(int af, const void *src, char *dst, size_t size); |
320 | char *strptime (const char *buf, const char *format, struct tm *tm); | 351 | |
321 | char *ctime (const time_t * clock); | 352 | int plibc_init(char *pszOrg, char *pszApp); |
322 | char *ctime_r (const time_t * clock, char *buf); | 353 | void plibc_shutdown(); |
323 | const char *inet_ntop (int af, const void *src, char *dst, size_t size); | 354 | int plibc_initialized(); |
324 | int plibc_init (char *pszOrg, char *pszApp); | 355 | int plibc_conv_to_win_path_ex(const char *pszUnix, char *pszWindows, int derefLinks); |
325 | void plibc_shutdown (); | 356 | void _SetErrnoFromWinError(long lWinError, char *pszCaller, int iLine); |
326 | int plibc_initialized (); | 357 | void SetErrnoFromWinsockError(long lWinError); |
327 | int plibc_conv_to_win_path_ex (const char *pszUnix, char *pszWindows, | 358 | void SetHErrnoFromWinError(long lWinError); |
328 | int derefLinks); | 359 | void SetErrnoFromHRESULT(HRESULT hRes); |
329 | void _SetErrnoFromWinError (long lWinError, char *pszCaller, int iLine); | 360 | int GetErrnoFromWinsockError(long lWinError); |
330 | void SetErrnoFromWinsockError (long lWinError); | 361 | FILE *_win_fopen(const char *filename, const char *mode); |
331 | void SetHErrnoFromWinError (long lWinError); | 362 | DIR *_win_opendir(const char *dirname); |
332 | void SetErrnoFromHRESULT (HRESULT hRes); | 363 | int _win_open(const char *filename, int oflag, ...); |
333 | FILE *_win_fopen (const char *filename, const char *mode); | ||
334 | DIR *_win_opendir (const char *dirname); | ||
335 | int _win_open (const char *filename, int oflag, ...); | ||
336 | |||
337 | #ifdef ENABLE_NLS | 364 | #ifdef ENABLE_NLS |
338 | char *_win_bindtextdomain (const char *domainname, const char *dirname); | 365 | char *_win_bindtextdomain(const char *domainname, const char *dirname); |
339 | 366 | #endif | |
340 | #endif /* */ | 367 | int _win_chdir(const char *path); |
341 | int _win_chdir (const char *path); | 368 | int _win_close(int fd); |
342 | int _win_close (int fd); | 369 | int _win_creat(const char *path, mode_t mode); |
343 | int _win_creat (const char *path, mode_t mode); | 370 | char *_win_ctime(const time_t *clock); |
344 | int _win_fstat (int handle, struct stat *buffer); | 371 | char *_win_ctime_r(const time_t *clock, char *buf); |
345 | int _win_ftruncate (int fildes, off_t length); | 372 | int _win_fstat(int handle, struct stat *buffer); |
346 | int _win_kill (pid_t pid, int sig); | 373 | int _win_ftruncate(int fildes, off_t length); |
347 | int _win_pipe (int *phandles); | 374 | void _win_gettimeofday(struct timeval *tp, void *tzp); |
348 | int _win_rmdir (const char *path); | 375 | int _win_kill(pid_t pid, int sig); |
349 | int _win_access (const char *path, int mode); | 376 | int _win_pipe(int *phandles); |
350 | int _win_chmod (const char *filename, int pmode); | 377 | int _win_rmdir(const char *path); |
351 | char *realpath (const char *file_name, char *resolved_name); | 378 | int _win_access( const char *path, int mode ); |
352 | long _win_random (void); | 379 | int _win_chmod(const char *filename, int pmode); |
353 | int _win_remove (const char *path); | 380 | char *realpath(const char *file_name, char *resolved_name); |
354 | int _win_rename (const char *oldname, const char *newname); | 381 | long _win_random(void); |
355 | int _win_stat (const char *path, struct stat *buffer); | 382 | int _win_remove(const char *path); |
356 | int _win_stat64 (const char *path, struct stat64 *buffer); | 383 | int _win_rename(const char *oldname, const char *newname); |
357 | int _win_unlink (const char *filename); | 384 | int _win_stat(const char *path, struct stat *buffer); |
358 | int _win_write (int fildes, const void *buf, size_t nbyte); | 385 | int _win_stat64(const char *path, struct stat64 *buffer); |
359 | int _win_read (int fildes, void *buf, size_t nbyte); | 386 | int _win_unlink(const char *filename); |
360 | size_t _win_fwrite (const void *buffer, size_t size, size_t count, | 387 | int _win_write(int fildes, const void *buf, size_t nbyte); |
361 | FILE * stream); | 388 | int _win_read(int fildes, void *buf, size_t nbyte); |
362 | size_t _win_fread (void *buffer, size_t size, size_t count, FILE * stream); | 389 | size_t _win_fwrite(const void *buffer, size_t size, size_t count, FILE *stream); |
363 | int _win_symlink (const char *path1, const char *path2); | 390 | size_t _win_fread( void *buffer, size_t size, size_t count, FILE *stream ); |
364 | void *_win_mmap (void *start, size_t len, int access, int flags, int fd, | 391 | int _win_symlink(const char *path1, const char *path2); |
365 | unsigned long long offset); | 392 | void *_win_mmap(void *start, size_t len, int access, int flags, int fd, |
366 | int _win_munmap (void *start, size_t length); | 393 | unsigned long long offset); |
367 | int _win_lstat (const char *path, struct stat *buf); | 394 | int _win_munmap(void *start, size_t length); |
368 | int _win_lstat64 (const char *path, struct stat64 *buf); | 395 | int _win_lstat(const char *path, struct stat *buf); |
369 | int _win_readlink (const char *path, char *buf, size_t bufsize); | 396 | int _win_lstat64(const char *path, struct stat64 *buf); |
370 | int _win_accept (SOCKET s, struct sockaddr *addr, int *addrlen); | 397 | int _win_readlink(const char *path, char *buf, size_t bufsize); |
371 | int _win_printf (const char *format, ...); | 398 | int _win_accept(SOCKET s, struct sockaddr *addr, int *addrlen); |
372 | int _win_fprintf (FILE * f, const char *format, ...); | 399 | int _win_printf(const char *format,...); |
373 | int _win_vprintf (const char *format, va_list ap); | 400 | int _win_fprintf(FILE *f,const char *format,...); |
374 | int _win_vfprintf (FILE * stream, const char *format, va_list arg_ptr); | 401 | int _win_vprintf(const char *format, va_list ap); |
375 | int _win_vsprintf (char *dest, const char *format, va_list arg_ptr); | 402 | int _win_vfprintf(FILE *stream, const char *format, va_list arg_ptr); |
376 | int _win_vsnprintf (char *str, size_t size, const char *format, | 403 | int _win_vsprintf(char *dest,const char *format, va_list arg_ptr); |
377 | va_list arg_ptr); | 404 | int _win_vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr); |
378 | int _win_snprintf (char *str, size_t size, const char *format, ...); | 405 | int _win_snprintf(char *str,size_t size,const char *format,...); |
379 | int _win_sprintf (char *dest, const char *format, ...); | 406 | int _win_sprintf(char *dest,const char *format,...); |
380 | int _win_vsscanf (const char *str, const char *format, va_list arg_ptr); | 407 | int _win_vsscanf(const char* str, const char* format, va_list arg_ptr); |
381 | int _win_sscanf (const char *str, const char *format, ...); | 408 | int _win_sscanf(const char *str, const char *format, ...); |
382 | int _win_vfscanf (FILE * stream, const char *format, va_list arg_ptr); | 409 | int _win_vfscanf(FILE *stream, const char *format, va_list arg_ptr); |
383 | int _win_vscanf (const char *format, va_list arg_ptr); | 410 | int _win_vscanf(const char *format, va_list arg_ptr); |
384 | int _win_scanf (const char *format, ...); | 411 | int _win_scanf(const char *format, ...); |
385 | int _win_fscanf (FILE * stream, const char *format, ...); | 412 | int _win_fscanf(FILE *stream, const char *format, ...); |
386 | pid_t _win_waitpid (pid_t pid, int *stat_loc, int options); | 413 | pid_t _win_waitpid(pid_t pid, int *stat_loc, int options); |
387 | int _win_bind (SOCKET s, const struct sockaddr *name, int namelen); | 414 | int _win_bind(SOCKET s, const struct sockaddr *name, int namelen); |
388 | int _win_connect (SOCKET s, const struct sockaddr *name, int namelen); | 415 | int _win_connect(SOCKET s,const struct sockaddr *name, int namelen); |
389 | int _win_getpeername (SOCKET s, struct sockaddr *name, int *namelen); | 416 | int _win_getpeername(SOCKET s, struct sockaddr *name, |
390 | int _win_getsockname (SOCKET s, struct sockaddr *name, int *namelen); | 417 | int *namelen); |
391 | int _win_getsockopt (SOCKET s, int level, int optname, char *optval, | 418 | int _win_getsockname(SOCKET s, struct sockaddr *name, |
392 | int *optlen); | 419 | int *namelen); |
393 | int _win_listen (SOCKET s, int backlog); | 420 | int _win_getsockopt(SOCKET s, int level, int optname, char *optval, |
394 | int _win_recv (SOCKET s, char *buf, int len, int flags); | 421 | int *optlen); |
395 | int _win_recvfrom (SOCKET s, void *buf, int len, int flags, | 422 | int _win_listen(SOCKET s, int backlog); |
396 | struct sockaddr *from, int *fromlen); | 423 | int _win_recv(SOCKET s, char *buf, int len, int flags); |
397 | int _win_select (int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, | 424 | int _win_recvfrom(SOCKET s, void *buf, int len, int flags, |
398 | const struct timeval *tv); | 425 | struct sockaddr *from, int *fromlen); |
399 | int _win_send (SOCKET s, const char *buf, int len, int flags); | 426 | int _win_select(int max_fd, fd_set * rfds, fd_set * wfds, fd_set * efds, |
400 | int _win_sendto (SOCKET s, const char *buf, int len, int flags, | 427 | const struct timeval *tv); |
401 | const struct sockaddr *to, int tolen); | 428 | int _win_send(SOCKET s, const char *buf, int len, int flags); |
402 | int _win_setsockopt (SOCKET s, int level, int optname, const void *optval, | 429 | int _win_sendto(SOCKET s, const char *buf, int len, int flags, |
403 | int optlen); | 430 | const struct sockaddr *to, int tolen); |
404 | int _win_shutdown (SOCKET s, int how); | 431 | int _win_setsockopt(SOCKET s, int level, int optname, const void *optval, |
405 | SOCKET _win_socket (int af, int type, int protocol); | 432 | int optlen); |
406 | struct hostent *_win_gethostbyaddr (const char *addr, int len, int type); | 433 | int _win_shutdown(SOCKET s, int how); |
407 | struct hostent *_win_gethostbyname (const char *name); | 434 | SOCKET _win_socket(int af, int type, int protocol); |
408 | struct hostent *gethostbyname2 (const char *name, int af); | 435 | struct hostent *_win_gethostbyaddr(const char *addr, int len, int type); |
409 | char *_win_strerror (int errnum); | 436 | struct hostent *_win_gethostbyname(const char *name); |
410 | int IsWinNT (); | 437 | struct hostent *gethostbyname2(const char *name, int af); |
411 | char *index (const char *s, int c); | 438 | char *_win_strerror(int errnum); |
439 | int IsWinNT(); | ||
440 | char *index(const char *s, int c); | ||
412 | 441 | ||
413 | #if !HAVE_STRNDUP | 442 | #if !HAVE_STRNDUP |
414 | char *strndup (const char *s, size_t n); | 443 | char *strndup (const char *s, size_t n); |
415 | 444 | #endif | |
416 | #endif /* */ | ||
417 | #if !HAVE_STRNLEN | 445 | #if !HAVE_STRNLEN |
418 | size_t strnlen (const char *str, size_t maxlen); | 446 | size_t strnlen (const char *str, size_t maxlen); |
419 | 447 | #endif | |
420 | #endif /* */ | ||
421 | 448 | ||
422 | #define strcasecmp(a, b) stricmp(a, b) | 449 | #define strcasecmp(a, b) stricmp(a, b) |
423 | #define strncasecmp(a, b, c) strnicmp(a, b, c) | 450 | #define strncasecmp(a, b, c) strnicmp(a, b, c) |
424 | 451 | ||
425 | #endif /* WINDOWS */ | 452 | #endif /* WINDOWS */ |
426 | 453 | ||
427 | #ifndef WINDOWS | 454 | #ifndef WINDOWS |
428 | #define DIR_SEPARATOR '/' | 455 | #define DIR_SEPARATOR '/' |
429 | #define DIR_SEPARATOR_STR "/" | 456 | #define DIR_SEPARATOR_STR "/" |
430 | #define PATH_SEPARATOR ';' | 457 | #define PATH_SEPARATOR ';' |
431 | #define PATH_SEPARATOR_STR ";" | 458 | #define PATH_SEPARATOR_STR ";" |
432 | #define NEWLINE "\n" | 459 | #define NEWLINE "\n" |
433 | 460 | ||
434 | #ifdef ENABLE_NLS | 461 | #ifdef ENABLE_NLS |
435 | #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) | 462 | #define BINDTEXTDOMAIN(d, n) bindtextdomain(d, n) |
436 | #endif /* */ | 463 | #endif |
437 | #define CREAT(p, m) creat(p, m) | 464 | #define CREAT(p, m) creat(p, m) |
438 | #undef FOPEN | 465 | #define PLIBC_CTIME(c) ctime(c) |
439 | #define FOPEN(f, m) fopen(f, m) | 466 | #define CTIME_R(c, b) ctime_r(c, b) |
440 | #define FTRUNCATE(f, l) ftruncate(f, l) | 467 | #undef FOPEN |
441 | #define OPENDIR(d) opendir(d) | 468 | #define FOPEN(f, m) fopen(f, m) |
442 | #define OPEN open | 469 | #define FTRUNCATE(f, l) ftruncate(f, l) |
443 | #define CHDIR(d) chdir(d) | 470 | #define OPENDIR(d) opendir(d) |
444 | #define CLOSE(f) close(f) | 471 | #define OPEN open |
445 | #define LSEEK(f, o, w) lseek(f, o, w) | 472 | #define CHDIR(d) chdir(d) |
446 | #define RMDIR(f) rmdir(f) | 473 | #define CLOSE(f) close(f) |
447 | #define ACCESS(p, m) access(p, m) | 474 | #define LSEEK(f, o, w) lseek(f, o, w) |
448 | #define CHMOD(f, p) chmod(f, p) | 475 | #define RMDIR(f) rmdir(f) |
449 | #define FSTAT(h, b) fstat(h, b) | 476 | #define ACCESS(p, m) access(p, m) |
450 | #define PLIBC_KILL(p, s) kill(p, s) | 477 | #define CHMOD(f, p) chmod(f, p) |
451 | #define PIPE(h) pipe(h) | 478 | #define FSTAT(h, b) fstat(h, b) |
452 | #define REMOVE(p) remove(p) | 479 | #define PLIBC_KILL(p, s) kill(p, s) |
453 | #define RENAME(o, n) rename(o, n) | 480 | #define PIPE(h) pipe(h) |
454 | #define STAT(p, b) stat(p, b) | 481 | #define REMOVE(p) remove(p) |
455 | #define STAT64(p, b) stat64(p, b) | 482 | #define RENAME(o, n) rename(o, n) |
456 | #define UNLINK(f) unlink(f) | 483 | #define STAT(p, b) stat(p, b) |
457 | #define WRITE(f, b, n) write(f, b, n) | 484 | #define STAT64(p, b) stat64(p, b) |
458 | #define READ(f, b, n) read(f, b, n) | 485 | #define UNLINK(f) unlink(f) |
459 | #define GN_FREAD(b, s, c, f) fread(b, s, c, f) | 486 | #define WRITE(f, b, n) write(f, b, n) |
460 | #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) | 487 | #define READ(f, b, n) read(f, b, n) |
461 | #define SYMLINK(a, b) symlink(a, b) | 488 | #define GN_FREAD(b, s, c, f) fread(b, s, c, f) |
462 | #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) | 489 | #define GN_FWRITE(b, s, c, f) fwrite(b, s, c, f) |
463 | #define MUNMAP(s, l) munmap(s, l) | 490 | #define SYMLINK(a, b) symlink(a, b) |
464 | #define STRERROR(i) strerror(i) | 491 | #define MMAP(s, l, p, f, d, o) mmap(s, l, p, f, d, o) |
465 | #define RANDOM() random() | 492 | #define MUNMAP(s, l) munmap(s, l) |
466 | #define READLINK(p, b, s) readlink(p, b, s) | 493 | #define STRERROR(i) strerror(i) |
467 | #define LSTAT(p, b) lstat(p, b) | 494 | #define RANDOM() random() |
468 | #define LSTAT64(p, b) lstat64(p, b) | 495 | #define READLINK(p, b, s) readlink(p, b, s) |
469 | #define PRINTF printf | 496 | #define LSTAT(p, b) lstat(p, b) |
470 | #define FPRINTF fprintf | 497 | #define LSTAT64(p, b) lstat64(p, b) |
471 | #define VPRINTF(f, a) vprintf(f, a) | 498 | #define PRINTF printf |
472 | #define VFPRINTF(s, f, a) vfprintf(s, f, a) | 499 | #define FPRINTF fprintf |
473 | #define VSPRINTF(d, f, a) vsprintf(d, f, a) | 500 | #define VPRINTF(f, a) vprintf(f, a) |
474 | #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) | 501 | #define VFPRINTF(s, f, a) vfprintf(s, f, a) |
475 | #define _REAL_SNPRINTF snprintf | 502 | #define VSPRINTF(d, f, a) vsprintf(d, f, a) |
476 | #define SPRINTF sprintf | 503 | #define VSNPRINTF(str, size, fmt, a) vsnprintf(str, size, fmt, a) |
477 | #define VSSCANF(s, f, a) vsscanf(s, f, a) | 504 | #define _REAL_SNPRINTF snprintf |
478 | #define SSCANF sscanf | 505 | #define SPRINTF sprintf |
479 | #define VFSCANF(s, f, a) vfscanf(s, f, a) | 506 | #define VSSCANF(s, f, a) vsscanf(s, f, a) |
480 | #define VSCANF(f, a) vscanf(f, a) | 507 | #define SSCANF sscanf |
481 | #define SCANF scanf | 508 | #define VFSCANF(s, f, a) vfscanf(s, f, a) |
482 | #define FSCANF fscanf | 509 | #define VSCANF(f, a) vscanf(f, a) |
483 | #define WAITPID(p, s, o) waitpid(p, s, o) | 510 | #define SCANF scanf |
484 | #define ACCEPT(s, a, l) accept(s, a, l) | 511 | #define FSCANF fscanf |
485 | #define BIND(s, n, l) bind(s, n, l) | 512 | #define WAITPID(p, s, o) waitpid(p, s, o) |
486 | #define CONNECT(s, n, l) connect(s, n, l) | 513 | #define ACCEPT(s, a, l) accept(s, a, l) |
487 | #define GETPEERNAME(s, n, l) getpeername(s, n, l) | 514 | #define BIND(s, n, l) bind(s, n, l) |
488 | #define GETSOCKNAME(s, n, l) getsockname(s, n, l) | 515 | #define CONNECT(s, n, l) connect(s, n, l) |
489 | #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) | 516 | #define GETPEERNAME(s, n, l) getpeername(s, n, l) |
490 | #define LISTEN(s, b) listen(s, b) | 517 | #define GETSOCKNAME(s, n, l) getsockname(s, n, l) |
491 | #define RECV(s, b, l, f) recv(s, b, l, f) | 518 | #define GETSOCKOPT(s, l, o, v, p) getsockopt(s, l, o, v, p) |
492 | #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) | 519 | #define LISTEN(s, b) listen(s, b) |
493 | #define SELECT(n, r, w, e, t) select(n, r, w, e, t) | 520 | #define RECV(s, b, l, f) recv(s, b, l, f) |
494 | #define SEND(s, b, l, f) send(s, b, l, f) | 521 | #define RECVFROM(s, b, l, f, r, o) recvfrom(s, b, l, f, r, o) |
495 | #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) | 522 | #define SELECT(n, r, w, e, t) select(n, r, w, e, t) |
496 | #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) | 523 | #define SEND(s, b, l, f) send(s, b, l, f) |
497 | #define SHUTDOWN(s, h) shutdown(s, h) | 524 | #define SENDTO(s, b, l, f, o, n) sendto(s, b, l, f, o, n) |
498 | #define SOCKET(a, t, p) socket(a, t, p) | 525 | #define SETSOCKOPT(s, l, o, v, n) setsockopt(s, l, o, v, n) |
499 | #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) | 526 | #define SHUTDOWN(s, h) shutdown(s, h) |
500 | #define GETHOSTBYNAME(n) gethostbyname(n) | 527 | #define SOCKET(a, t, p) socket(a, t, p) |
501 | #else /* */ | 528 | #define GETHOSTBYADDR(a, l, t) gethostbyname(a, l, t) |
502 | #define DIR_SEPARATOR '\\' | 529 | #define GETHOSTBYNAME(n) gethostbyname(n) |
503 | #define DIR_SEPARATOR_STR "\\" | 530 | #define GETTIMEOFDAY(t, n) gettimeofday(t, n) |
504 | #define PATH_SEPARATOR ':' | 531 | #define INSQUE(e, p) insque(e, p) |
505 | #define PATH_SEPARATOR_STR ":" | 532 | #define REMQUE(e) remque(e) |
506 | #define NEWLINE "\r\n" | 533 | #define HSEARCH(i, a) hsearch(i, a) |
534 | #define HCREATE(n) hcreate(n) | ||
535 | #define HDESTROY() hdestroy() | ||
536 | #define HSEARCH_R(i, a, r, h) hsearch_r(i, a, r, h) | ||
537 | #define HCREATE_R(n, h) hcreate_r(n, h) | ||
538 | #define HDESTROY_R(h) hdestroy_r(h) | ||
539 | #define TSEARCH(k, r, c) tsearch(k, r, c) | ||
540 | #define TFIND(k, r, c) tfind(k, r, c) | ||
541 | #define TDELETE(k, r, c) tdelete(k, r, c) | ||
542 | #define TWALK(r, a) twalk(r, a) | ||
543 | #define TDESTROY(r, f) tdestroy(r, f) | ||
544 | #define LFIND(k, b, n, s, c) lfind(k, b, n, s, c) | ||
545 | #define LSEARCH(k, b, n, s, c) lsearch(k, b, n, s, c) | ||
546 | #else | ||
547 | #define DIR_SEPARATOR '\\' | ||
548 | #define DIR_SEPARATOR_STR "\\" | ||
549 | #define PATH_SEPARATOR ':' | ||
550 | #define PATH_SEPARATOR_STR ":" | ||
551 | #define NEWLINE "\r\n" | ||
507 | 552 | ||
508 | #ifdef ENABLE_NLS | 553 | #ifdef ENABLE_NLS |
509 | #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) | 554 | #define BINDTEXTDOMAIN(d, n) _win_bindtextdomain(d, n) |
510 | #endif /* */ | 555 | #endif |
511 | #define CREAT(p, m) _win_creat(p, m) | 556 | #define CREAT(p, m) _win_creat(p, m) |
512 | #define FOPEN(f, m) _win_fopen(f, m) | 557 | #define PLIBC_CTIME(c) _win_ctime(c) |
513 | #define FTRUNCATE(f, l) _win_ftruncate(f, l) | 558 | #define CTIME_R(c, b) _win_ctime_r(c, b) |
514 | #define OPENDIR(d) _win_opendir(d) | 559 | #define FOPEN(f, m) _win_fopen(f, m) |
515 | #define OPEN _win_open | 560 | #define FTRUNCATE(f, l) _win_ftruncate(f, l) |
516 | #define CHDIR(d) _win_chdir(d) | 561 | #define OPENDIR(d) _win_opendir(d) |
517 | #define CLOSE(f) _win_close(f) | 562 | #define OPEN _win_open |
518 | #define PLIBC_KILL(p, s) _win_kill(p, s) | 563 | #define CHDIR(d) _win_chdir(d) |
519 | #define LSEEK(f, o, w) _win_lseek(f, o, w) | 564 | #define CLOSE(f) _win_close(f) |
520 | #define FSTAT(h, b) _win_fstat(h, b) | 565 | #define PLIBC_KILL(p, s) _win_kill(p, s) |
521 | #define RMDIR(f) _win_rmdir(f) | 566 | #define LSEEK(f, o, w) _win_lseek(f, o, w) |
522 | #define ACCESS(p, m) _win_access(p, m) | 567 | #define FSTAT(h, b) _win_fstat(h, b) |
523 | #define CHMOD(f, p) _win_chmod(f, p) | 568 | #define RMDIR(f) _win_rmdir(f) |
524 | #define PIPE(h) _win_pipe(h) | 569 | #define ACCESS(p, m) _win_access(p, m) |
525 | #define RANDOM() _win_random() | 570 | #define CHMOD(f, p) _win_chmod(f, p) |
526 | #define REMOVE(p) _win_remove(p) | 571 | #define PIPE(h) _win_pipe(h) |
527 | #define RENAME(o, n) _win_rename(o, n) | 572 | #define RANDOM() _win_random() |
528 | #define STAT(p, b) _win_stat(p, b) | 573 | #define REMOVE(p) _win_remove(p) |
529 | #define STAT64(p, b) _win_stat64(p, b) | 574 | #define RENAME(o, n) _win_rename(o, n) |
530 | #define UNLINK(f) _win_unlink(f) | 575 | #define STAT(p, b) _win_stat(p, b) |
531 | #define WRITE(f, b, n) _win_write(f, b, n) | 576 | #define STAT64(p, b) _win_stat64(p, b) |
532 | #define READ(f, b, n) _win_read(f, b, n) | 577 | #define UNLINK(f) _win_unlink(f) |
533 | #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) | 578 | #define WRITE(f, b, n) _win_write(f, b, n) |
534 | #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) | 579 | #define READ(f, b, n) _win_read(f, b, n) |
535 | #define SYMLINK(a, b) _win_symlink(a, b) | 580 | #define GN_FREAD(b, s, c, f) _win_fread(b, s, c, f) |
536 | #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) | 581 | #define GN_FWRITE(b, s, c, f) _win_fwrite(b, s, c, f) |
537 | #define MUNMAP(s, l) _win_munmap(s, l) | 582 | #define SYMLINK(a, b) _win_symlink(a, b) |
538 | #define STRERROR(i) _win_strerror(i) | 583 | #define MMAP(s, l, p, f, d, o) _win_mmap(s, l, p, f, d, o) |
539 | #define READLINK(p, b, s) _win_readlink(p, b, s) | 584 | #define MUNMAP(s, l) _win_munmap(s, l) |
540 | #define LSTAT(p, b) _win_lstat(p, b) | 585 | #define STRERROR(i) _win_strerror(i) |
541 | #define LSTAT64(p, b) _win_lstat64(p, b) | 586 | #define READLINK(p, b, s) _win_readlink(p, b, s) |
542 | #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) | 587 | #define LSTAT(p, b) _win_lstat(p, b) |
543 | #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) | 588 | #define LSTAT64(p, b) _win_lstat64(p, b) |
544 | #define VPRINTF(f, a) _win_vprintf(f, a) | 589 | #define PRINTF(f, ...) _win_printf(f , __VA_ARGS__) |
545 | #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) | 590 | #define FPRINTF(fil, fmt, ...) _win_fprintf(fil, fmt, __VA_ARGS__) |
546 | #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) | 591 | #define VPRINTF(f, a) _win_vprintf(f, a) |
547 | #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) | 592 | #define VFPRINTF(s, f, a) _win_vfprintf(s, f, a) |
548 | #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) | 593 | #define VSPRINTF(d, f, a) _win_vsprintf(d, f, a) |
549 | #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) | 594 | #define VSNPRINTF(str, size, fmt, a) _win_vsnprintf(str, size, fmt, a) |
550 | #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) | 595 | #define _REAL_SNPRINTF(str, size, fmt, ...) _win_snprintf(str, size, fmt, __VA_ARGS__) |
551 | #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) | 596 | #define SPRINTF(d, f, ...) _win_sprintf(d, f, __VA_ARGS__) |
552 | #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) | 597 | #define VSSCANF(s, f, a) _win_vsscanf(s, f, a) |
553 | #define VSCANF(f, a) _win_vscanf(f, a) | 598 | #define SSCANF(s, f, ...) _win_sscanf(s, f, __VA_ARGS__) |
554 | #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) | 599 | #define VFSCANF(s, f, a) _win_vfscanf(s, f, a) |
555 | #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) | 600 | #define VSCANF(f, a) _win_vscanf(f, a) |
556 | #define WAITPID(p, s, o) _win_waitpid(p, s, o) | 601 | #define SCANF(f, ...) _win_scanf(f, __VA_ARGS__) |
557 | #define ACCEPT(s, a, l) _win_accept(s, a, l) | 602 | #define FSCANF(s, f, ...) _win_fscanf(s, f, __VA_ARGS__) |
558 | #define BIND(s, n, l) _win_bind(s, n, l) | 603 | #define WAITPID(p, s, o) _win_waitpid(p, s, o) |
559 | #define CONNECT(s, n, l) _win_connect(s, n, l) | 604 | #define ACCEPT(s, a, l) _win_accept(s, a, l) |
560 | #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) | 605 | #define BIND(s, n, l) _win_bind(s, n, l) |
561 | #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) | 606 | #define CONNECT(s, n, l) _win_connect(s, n, l) |
562 | #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) | 607 | #define GETPEERNAME(s, n, l) _win_getpeername(s, n, l) |
563 | #define LISTEN(s, b) _win_listen(s, b) | 608 | #define GETSOCKNAME(s, n, l) _win_getsockname(s, n, l) |
564 | #define RECV(s, b, l, f) _win_recv(s, b, l, f) | 609 | #define GETSOCKOPT(s, l, o, v, p) _win_getsockopt(s, l, o, v, p) |
565 | #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) | 610 | #define LISTEN(s, b) _win_listen(s, b) |
566 | #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) | 611 | #define RECV(s, b, l, f) _win_recv(s, b, l, f) |
567 | #define SEND(s, b, l, f) _win_send(s, b, l, f) | 612 | #define RECVFROM(s, b, l, f, r, o) _win_recvfrom(s, b, l, f, r, o) |
568 | #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) | 613 | #define SELECT(n, r, w, e, t) _win_select(n, r, w, e, t) |
569 | #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) | 614 | #define SEND(s, b, l, f) _win_send(s, b, l, f) |
570 | #define SHUTDOWN(s, h) _win_shutdown(s, h) | 615 | #define SENDTO(s, b, l, f, o, n) _win_sendto(s, b, l, f, o, n) |
571 | #define SOCKET(a, t, p) _win_socket(a, t, p) | 616 | #define SETSOCKOPT(s, l, o, v, n) _win_setsockopt(s, l, o, v, n) |
572 | #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) | 617 | #define SHUTDOWN(s, h) _win_shutdown(s, h) |
573 | #define GETHOSTBYNAME(n) _win_gethostbyname(n) | 618 | #define SOCKET(a, t, p) _win_socket(a, t, p) |
574 | #endif /* */ | 619 | #define GETHOSTBYADDR(a, l, t) _win_gethostbyname(a, l, t) |
620 | #define GETHOSTBYNAME(n) _win_gethostbyname(n) | ||
621 | #define GETTIMEOFDAY(t, n) _win_gettimeofday(t, n) | ||
622 | #define INSQUE(e, p) _win_insque(e, p) | ||
623 | #define REMQUE(e) _win_remque(e) | ||
624 | #define HSEARCH(i, a) _win_hsearch(i, a) | ||
625 | #define HCREATE(n) _win_hcreate(n) | ||
626 | #define HDESTROY() _win_hdestroy() | ||
627 | #define HSEARCH_R(i, a, r, h) _win_hsearch_r(i, a, r, h) | ||
628 | #define HCREATE_R(n, h) _win_hcreate_r(n, h) | ||
629 | #define HDESTROY_R(h) _win_hdestroy_r(h) | ||
630 | #define TSEARCH(k, r, c) _win_tsearch(k, r, c) | ||
631 | #define TFIND(k, r, c) _win_tfind(k, r, c) | ||
632 | #define TDELETE(k, r, c) _win_tdelete(k, r, c) | ||
633 | #define TWALK(r, a) _win_twalk(r, a) | ||
634 | #define TDESTROY(r, f) _win_tdestroy(r, f) | ||
635 | #define LFIND(k, b, n, s, c) _win_lfind(k, b, n, s, c) | ||
636 | #define LSEARCH(k, b, n, s, c) _win_lsearch(k, b, n, s, c) | ||
637 | #endif | ||
638 | |||
639 | /* search.h */ | ||
640 | |||
641 | /* Prototype structure for a linked-list data structure. | ||
642 | This is the type used by the `insque' and `remque' functions. */ | ||
643 | |||
644 | struct PLIBC_SEARCH_QELEM | ||
645 | { | ||
646 | struct qelem *q_forw; | ||
647 | struct qelem *q_back; | ||
648 | char q_data[1]; | ||
649 | }; | ||
650 | |||
651 | |||
652 | /* Insert ELEM into a doubly-linked list, after PREV. */ | ||
653 | void _win_insque (void *__elem, void *__prev); | ||
654 | |||
655 | /* Unlink ELEM from the doubly-linked list that it is in. */ | ||
656 | void _win_remque (void *__elem); | ||
657 | |||
658 | |||
659 | /* For use with hsearch(3). */ | ||
660 | typedef int (*PLIBC_SEARCH__compar_fn_t) (__const void *, __const void *); | ||
661 | |||
662 | typedef PLIBC_SEARCH__compar_fn_t _win_comparison_fn_t; | ||
663 | |||
664 | /* Action which shall be performed in the call the hsearch. */ | ||
665 | typedef enum | ||
666 | { | ||
667 | PLIBC_SEARCH_FIND, | ||
668 | PLIBC_SEARCH_ENTER | ||
669 | } | ||
670 | PLIBC_SEARCH_ACTION; | ||
671 | |||
672 | typedef struct PLIBC_SEARCH_entry | ||
673 | { | ||
674 | char *key; | ||
675 | void *data; | ||
676 | } | ||
677 | PLIBC_SEARCH_ENTRY; | ||
678 | |||
679 | /* The reentrant version has no static variables to maintain the state. | ||
680 | Instead the interface of all functions is extended to take an argument | ||
681 | which describes the current status. */ | ||
682 | typedef struct _PLIBC_SEARCH_ENTRY | ||
683 | { | ||
684 | unsigned int used; | ||
685 | PLIBC_SEARCH_ENTRY entry; | ||
686 | } | ||
687 | _PLIBC_SEARCH_ENTRY; | ||
688 | |||
689 | |||
690 | /* Family of hash table handling functions. The functions also | ||
691 | have reentrant counterparts ending with _r. The non-reentrant | ||
692 | functions all work on a signle internal hashing table. */ | ||
693 | |||
694 | /* Search for entry matching ITEM.key in internal hash table. If | ||
695 | ACTION is `FIND' return found entry or signal error by returning | ||
696 | NULL. If ACTION is `ENTER' replace existing data (if any) with | ||
697 | ITEM.data. */ | ||
698 | PLIBC_SEARCH_ENTRY *_win_hsearch (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action); | ||
699 | |||
700 | /* Create a new hashing table which will at most contain NEL elements. */ | ||
701 | int _win_hcreate (size_t __nel); | ||
702 | |||
703 | /* Destroy current internal hashing table. */ | ||
704 | void _win_hdestroy (void); | ||
705 | |||
706 | /* Data type for reentrant functions. */ | ||
707 | struct PLIBC_SEARCH_hsearch_data | ||
708 | { | ||
709 | struct _PLIBC_SEARCH_ENTRY *table; | ||
710 | unsigned int size; | ||
711 | unsigned int filled; | ||
712 | }; | ||
713 | |||
714 | /* Reentrant versions which can handle multiple hashing tables at the | ||
715 | same time. */ | ||
716 | int _win_hsearch_r (PLIBC_SEARCH_ENTRY __item, PLIBC_SEARCH_ACTION __action, PLIBC_SEARCH_ENTRY **__retval, | ||
717 | struct PLIBC_SEARCH_hsearch_data *__htab); | ||
718 | int _win_hcreate_r (size_t __nel, struct PLIBC_SEARCH_hsearch_data *__htab); | ||
719 | void _win_hdestroy_r (struct PLIBC_SEARCH_hsearch_data *__htab); | ||
720 | |||
721 | |||
722 | /* The tsearch routines are very interesting. They make many | ||
723 | assumptions about the compiler. It assumes that the first field | ||
724 | in node must be the "key" field, which points to the datum. | ||
725 | Everything depends on that. */ | ||
726 | /* For tsearch */ | ||
727 | typedef enum | ||
728 | { | ||
729 | PLIBC_SEARCH_preorder, | ||
730 | PLIBC_SEARCH_postorder, | ||
731 | PLIBC_SEARCH_endorder, | ||
732 | PLIBC_SEARCH_leaf | ||
733 | } | ||
734 | PLIBC_SEARCH_VISIT; | ||
735 | |||
736 | /* Search for an entry matching the given KEY in the tree pointed to | ||
737 | by *ROOTP and insert a new element if not found. */ | ||
738 | void *_win_tsearch (__const void *__key, void **__rootp, | ||
739 | PLIBC_SEARCH__compar_fn_t __compar); | ||
740 | |||
741 | /* Search for an entry matching the given KEY in the tree pointed to | ||
742 | by *ROOTP. If no matching entry is available return NULL. */ | ||
743 | void *_win_tfind (__const void *__key, void *__const *__rootp, | ||
744 | PLIBC_SEARCH__compar_fn_t __compar); | ||
745 | |||
746 | /* Remove the element matching KEY from the tree pointed to by *ROOTP. */ | ||
747 | void *_win_tdelete (__const void *__restrict __key, | ||
748 | void **__restrict __rootp, | ||
749 | PLIBC_SEARCH__compar_fn_t __compar); | ||
750 | |||
751 | typedef void (*PLIBC_SEARCH__action_fn_t) (__const void *__nodep, PLIBC_SEARCH_VISIT __value, | ||
752 | int __level); | ||
753 | |||
754 | /* Walk through the whole tree and call the ACTION callback for every node | ||
755 | or leaf. */ | ||
756 | void _win_twalk (__const void *__root, PLIBC_SEARCH__action_fn_t __action); | ||
757 | |||
758 | /* Callback type for function to free a tree node. If the keys are atomic | ||
759 | data this function should do nothing. */ | ||
760 | typedef void (*PLIBC_SEARCH__free_fn_t) (void *__nodep); | ||
761 | |||
762 | /* Destroy the whole tree, call FREEFCT for each node or leaf. */ | ||
763 | void _win_tdestroy (void *__root, PLIBC_SEARCH__free_fn_t __freefct); | ||
764 | |||
765 | |||
766 | /* Perform linear search for KEY by comparing by COMPAR in an array | ||
767 | [BASE,BASE+NMEMB*SIZE). */ | ||
768 | void *_win_lfind (__const void *__key, __const void *__base, | ||
769 | size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); | ||
770 | |||
771 | /* Perform linear search for KEY by comparing by COMPAR function in | ||
772 | array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */ | ||
773 | void *_win_lsearch (__const void *__key, void *__base, | ||
774 | size_t *__nmemb, size_t __size, PLIBC_SEARCH__compar_fn_t __compar); | ||
775 | |||
575 | 776 | ||
576 | #ifdef __cplusplus | 777 | #ifdef __cplusplus |
577 | } | 778 | } |
578 | #endif /* */ | 779 | #endif |
780 | |||
579 | 781 | ||
580 | #endif //_PLIBC_H_ | 782 | #endif //_PLIBC_H_ |
581 | 783 | ||
582 | /* end of plibc.h */ | 784 | /* end of plibc.h */ |
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index a90b2b793..9ecb3e469 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -4,6 +4,7 @@ plugindir = $(libdir)/gnunet | |||
4 | 4 | ||
5 | if MINGW | 5 | if MINGW |
6 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -luuid -liconv -lstdc++ -lcomdlg32 -lgdi32 | 6 | WINFLAGS = -Wl,--no-undefined -Wl,--export-all-symbols -lole32 -lshell32 -luuid -liconv -lstdc++ -lcomdlg32 -lgdi32 |
7 | WINSRC = win.cc winproc.c | ||
7 | endif | 8 | endif |
8 | 9 | ||
9 | if USE_COVERAGE | 10 | if USE_COVERAGE |
@@ -45,7 +46,8 @@ libgnunetutil_la_SOURCES = \ | |||
45 | service.c \ | 46 | service.c \ |
46 | signal.c \ | 47 | signal.c \ |
47 | strings.c \ | 48 | strings.c \ |
48 | time.c | 49 | time.c \ |
50 | $(WINSRC) | ||
49 | 51 | ||
50 | 52 | ||
51 | libgnunetutil_la_LIBADD = \ | 53 | libgnunetutil_la_LIBADD = \ |
diff --git a/src/util/crypto_rsa.c b/src/util/crypto_rsa.c index c5a6140f6..650df814e 100644 --- a/src/util/crypto_rsa.c +++ b/src/util/crypto_rsa.c | |||
@@ -559,7 +559,10 @@ rsa_decode_key (const struct RsaPrivateKeyBinaryEncoded *encoding) | |||
559 | struct GNUNET_CRYPTO_RsaPrivateKey * | 559 | struct GNUNET_CRYPTO_RsaPrivateKey * |
560 | GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | 560 | GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) |
561 | { | 561 | { |
562 | #ifndef MINGW | ||
563 | // FIXME NILS | ||
562 | struct flock fl; | 564 | struct flock fl; |
565 | #endif | ||
563 | struct GNUNET_CRYPTO_RsaPrivateKey *ret; | 566 | struct GNUNET_CRYPTO_RsaPrivateKey *ret; |
564 | struct RsaPrivateKeyBinaryEncoded *enc; | 567 | struct RsaPrivateKeyBinaryEncoded *enc; |
565 | struct stat sbuf; | 568 | struct stat sbuf; |
@@ -581,11 +584,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
581 | "open", filename); | 584 | "open", filename); |
582 | return NULL; | 585 | return NULL; |
583 | } | 586 | } |
587 | #ifndef MINGW | ||
584 | memset (&fl, 0, sizeof (struct flock)); | 588 | memset (&fl, 0, sizeof (struct flock)); |
585 | fl.l_type = F_WRLCK; | 589 | fl.l_type = F_WRLCK; |
586 | fl.l_whence = SEEK_SET; | 590 | fl.l_whence = SEEK_SET; |
587 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); | 591 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); |
588 | cnt = 0; | 592 | cnt = 0; |
593 | |||
589 | while (0 != fcntl (fd, F_SETLK, &fl)) | 594 | while (0 != fcntl (fd, F_SETLK, &fl)) |
590 | { | 595 | { |
591 | sleep (1); | 596 | sleep (1); |
@@ -604,6 +609,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
604 | fl.l_whence = SEEK_SET; | 609 | fl.l_whence = SEEK_SET; |
605 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); | 610 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); |
606 | } | 611 | } |
612 | #endif | ||
607 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 613 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
608 | _("Creating a new private key. This may take a while.\n")); | 614 | _("Creating a new private key. This may take a while.\n")); |
609 | ret = GNUNET_CRYPTO_rsa_key_create (); | 615 | ret = GNUNET_CRYPTO_rsa_key_create (); |
@@ -612,6 +618,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
612 | GNUNET_assert (enc != NULL); | 618 | GNUNET_assert (enc != NULL); |
613 | GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len))); | 619 | GNUNET_assert (ntohs (enc->len) == WRITE (fd, enc, ntohs (enc->len))); |
614 | GNUNET_free (enc); | 620 | GNUNET_free (enc); |
621 | #ifndef MINGW | ||
615 | fdatasync (fd); | 622 | fdatasync (fd); |
616 | memset (&fl, 0, sizeof (struct flock)); | 623 | memset (&fl, 0, sizeof (struct flock)); |
617 | fl.l_type = F_UNLCK; | 624 | fl.l_type = F_UNLCK; |
@@ -621,6 +628,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
621 | if (0 != fcntl (fd, F_SETLK, &fl)) | 628 | if (0 != fcntl (fd, F_SETLK, &fl)) |
622 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 629 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
623 | "fcntl", filename); | 630 | "fcntl", filename); |
631 | #endif | ||
624 | GNUNET_assert (0 == CLOSE (fd)); | 632 | GNUNET_assert (0 == CLOSE (fd)); |
625 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 633 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
626 | _("Stored new private key in `%s'.\n"), filename); | 634 | _("Stored new private key in `%s'.\n"), filename); |
@@ -636,6 +644,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
636 | cnt = 0; | 644 | cnt = 0; |
637 | while (1) | 645 | while (1) |
638 | { | 646 | { |
647 | #ifndef MINGW | ||
639 | memset (&fl, 0, sizeof (struct flock)); | 648 | memset (&fl, 0, sizeof (struct flock)); |
640 | fl.l_type = F_RDLCK; | 649 | fl.l_type = F_RDLCK; |
641 | fl.l_whence = SEEK_SET; | 650 | fl.l_whence = SEEK_SET; |
@@ -658,11 +667,13 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
658 | sleep (1); | 667 | sleep (1); |
659 | continue; | 668 | continue; |
660 | } | 669 | } |
670 | #endif | ||
661 | if (0 != STAT (filename, &sbuf)) | 671 | if (0 != STAT (filename, &sbuf)) |
662 | { | 672 | { |
663 | /* eh, what!? File we opened is now gone!? */ | 673 | /* eh, what!? File we opened is now gone!? */ |
664 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 674 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, |
665 | "stat", filename); | 675 | "stat", filename); |
676 | #ifndef MINGW | ||
666 | memset (&fl, 0, sizeof (struct flock)); | 677 | memset (&fl, 0, sizeof (struct flock)); |
667 | fl.l_type = F_UNLCK; | 678 | fl.l_type = F_UNLCK; |
668 | fl.l_whence = SEEK_SET; | 679 | fl.l_whence = SEEK_SET; |
@@ -671,10 +682,12 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
671 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, | 682 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, |
672 | "fcntl", filename); | 683 | "fcntl", filename); |
673 | GNUNET_assert (0 == CLOSE (fd)); | 684 | GNUNET_assert (0 == CLOSE (fd)); |
685 | #endif | ||
674 | return NULL; | 686 | return NULL; |
675 | } | 687 | } |
676 | if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded)) | 688 | if (sbuf.st_size < sizeof (struct RsaPrivateKeyBinaryEncoded)) |
677 | { | 689 | { |
690 | #ifndef MINGW | ||
678 | /* maybe we got the read lock before the hostkey generating | 691 | /* maybe we got the read lock before the hostkey generating |
679 | process had a chance to get the write lock; give it up! */ | 692 | process had a chance to get the write lock; give it up! */ |
680 | memset (&fl, 0, sizeof (struct flock)); | 693 | memset (&fl, 0, sizeof (struct flock)); |
@@ -698,6 +711,7 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
698 | } | 711 | } |
699 | sleep (2); /* wait a bit longer! */ | 712 | sleep (2); /* wait a bit longer! */ |
700 | continue; | 713 | continue; |
714 | #endif | ||
701 | } | 715 | } |
702 | break; | 716 | break; |
703 | } | 717 | } |
@@ -713,12 +727,14 @@ GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename) | |||
713 | filename); | 727 | filename); |
714 | GNUNET_free (enc); | 728 | GNUNET_free (enc); |
715 | } | 729 | } |
730 | #ifndef MINGW | ||
716 | memset (&fl, 0, sizeof (struct flock)); | 731 | memset (&fl, 0, sizeof (struct flock)); |
717 | fl.l_type = F_UNLCK; | 732 | fl.l_type = F_UNLCK; |
718 | fl.l_whence = SEEK_SET; | 733 | fl.l_whence = SEEK_SET; |
719 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); | 734 | fl.l_len = sizeof (struct RsaPrivateKeyBinaryEncoded); |
720 | if (0 != fcntl (fd, F_SETLK, &fl)) | 735 | if (0 != fcntl (fd, F_SETLK, &fl)) |
721 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); | 736 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, "fcntl", filename); |
737 | #endif | ||
722 | GNUNET_assert (0 == CLOSE (fd)); | 738 | GNUNET_assert (0 == CLOSE (fd)); |
723 | return ret; | 739 | return ret; |
724 | } | 740 | } |
diff --git a/src/util/disk.c b/src/util/disk.c index f0fe9341b..5042f0867 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -157,7 +157,7 @@ GNUNET_DISK_get_blocks_available (const char *part) | |||
157 | szDrive[3] = 0; | 157 | szDrive[3] = 0; |
158 | if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) | 158 | if (!GetDiskFreeSpace (szDrive, &dwDummy, &dwDummy, &dwBlocks, &dwDummy)) |
159 | { | 159 | { |
160 | GNUNET_GE_LOG (GNUNET_ERROR_TYPE_WARNING, | 160 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
161 | _("`%s' failed for drive `%s': %u\n"), | 161 | _("`%s' failed for drive `%s': %u\n"), |
162 | "GetDiskFreeSpace", szDrive, GetLastError ()); | 162 | "GetDiskFreeSpace", szDrive, GetLastError ()); |
163 | 163 | ||
diff --git a/src/util/network.c b/src/util/network.c index b6cce5462..890b4c573 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -249,9 +249,12 @@ GNUNET_NETWORK_socket_create_from_accept (struct GNUNET_SCHEDULER_Handle | |||
249 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); | 249 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "accept"); |
250 | return NULL; | 250 | return NULL; |
251 | } | 251 | } |
252 | #ifndef MINGW | ||
253 | // FIXME NILS | ||
252 | if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC)) | 254 | if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC)) |
253 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 255 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
254 | "fcntl"); | 256 | "fcntl"); |
257 | #endif | ||
255 | if (addrlen > sizeof (addr)) | 258 | if (addrlen > sizeof (addr)) |
256 | { | 259 | { |
257 | GNUNET_break (0); | 260 | GNUNET_break (0); |
@@ -287,7 +290,7 @@ GNUNET_NETWORK_socket_create_from_accept (struct GNUNET_SCHEDULER_Handle | |||
287 | if (aret == GNUNET_NO) | 290 | if (aret == GNUNET_NO) |
288 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 291 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
289 | _("Access denied to `%s'\n"), | 292 | _("Access denied to `%s'\n"), |
290 | GNUNET_a2s(uaddr, addrlen)); | 293 | GNUNET_a2s(uaddr, addrlen)); |
291 | GNUNET_break (0 == SHUTDOWN (fd, SHUT_RDWR)); | 294 | GNUNET_break (0 == SHUTDOWN (fd, SHUT_RDWR)); |
292 | GNUNET_break (0 == CLOSE (fd)); | 295 | GNUNET_break (0 == CLOSE (fd)); |
293 | GNUNET_free (uaddr); | 296 | GNUNET_free (uaddr); |
@@ -432,9 +435,12 @@ try_connect (struct GNUNET_NETWORK_SocketHandle *sock) | |||
432 | sock->ai_pos = sock->ai_pos->ai_next; | 435 | sock->ai_pos = sock->ai_pos->ai_next; |
433 | continue; | 436 | continue; |
434 | } | 437 | } |
438 | #ifndef MINGW | ||
439 | // FIXME NILS | ||
435 | if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC)) | 440 | if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC)) |
436 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 441 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
437 | "fcntl"); | 442 | "fcntl"); |
443 | #endif | ||
438 | if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO)) | 444 | if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO)) |
439 | { | 445 | { |
440 | /* we'll treat this one as fatal */ | 446 | /* we'll treat this one as fatal */ |
@@ -524,7 +530,7 @@ connect_continuation (void *cls, | |||
524 | } | 530 | } |
525 | /* connect succeeded! clean up "ai" */ | 531 | /* connect succeeded! clean up "ai" */ |
526 | #if DEBUG_NETWORK | 532 | #if DEBUG_NETWORK |
527 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 533 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
528 | "Connection to `%s' succeeded!\n", | 534 | "Connection to `%s' succeeded!\n", |
529 | GNUNET_a2s(sock->addr, sock->addrlen)); | 535 | GNUNET_a2s(sock->addr, sock->addrlen)); |
530 | #endif | 536 | #endif |
@@ -619,9 +625,11 @@ GNUNET_NETWORK_socket_create_from_sockaddr (struct GNUNET_SCHEDULER_Handle | |||
619 | GNUNET_ERROR_TYPE_BULK, "socket"); | 625 | GNUNET_ERROR_TYPE_BULK, "socket"); |
620 | return NULL; | 626 | return NULL; |
621 | } | 627 | } |
628 | #ifndef MINGW | ||
622 | if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC)) | 629 | if (0 != fcntl (s, F_SETFD, fcntl (s, F_GETFD) | FD_CLOEXEC)) |
623 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 630 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
624 | "fcntl"); | 631 | "fcntl"); |
632 | #endif | ||
625 | if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO)) | 633 | if (GNUNET_SYSERR == socket_set_blocking (s, GNUNET_NO)) |
626 | { | 634 | { |
627 | /* we'll treat this one as fatal */ | 635 | /* we'll treat this one as fatal */ |
@@ -712,7 +720,7 @@ destroy_continuation (void *cls, | |||
712 | } | 720 | } |
713 | } | 721 | } |
714 | if (sock->sock != -1) | 722 | if (sock->sock != -1) |
715 | GNUNET_break (0 == CLOSE (sock->sock)); | 723 | GNUNET_break (0 == CLOSE (sock->sock)); |
716 | GNUNET_free_non_null (sock->addr); | 724 | GNUNET_free_non_null (sock->addr); |
717 | if (sock->ai != NULL) | 725 | if (sock->ai != NULL) |
718 | freeaddrinfo (sock->ai); | 726 | freeaddrinfo (sock->ai); |
@@ -810,7 +818,14 @@ receive_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
810 | } | 818 | } |
811 | GNUNET_assert (FD_ISSET (sh->sock, tc->read_ready)); | 819 | GNUNET_assert (FD_ISSET (sh->sock, tc->read_ready)); |
812 | RETRY: | 820 | RETRY: |
813 | ret = RECV (sh->sock, buffer, sh->max, MSG_DONTWAIT); | 821 | ret = RECV (sh->sock, buffer, sh->max, |
822 | #ifndef MINGW | ||
823 | // FIXME MINGW | ||
824 | MSG_DONTWAIT | ||
825 | #else | ||
826 | 0 | ||
827 | #endif | ||
828 | ); | ||
814 | if (ret == -1) | 829 | if (ret == -1) |
815 | { | 830 | { |
816 | if (errno == EINTR) | 831 | if (errno == EINTR) |
@@ -825,7 +840,7 @@ RETRY: | |||
825 | #if DEBUG_NETWORK | 840 | #if DEBUG_NETWORK |
826 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 841 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
827 | "receive_ready read %u/%u bytes from `%s'!\n", | 842 | "receive_ready read %u/%u bytes from `%s'!\n", |
828 | (unsigned int) ret, | 843 | (unsigned int) ret, |
829 | sh->max, | 844 | sh->max, |
830 | GNUNET_a2s(sh->addr, sh->addrlen)); | 845 | GNUNET_a2s(sh->addr, sh->addrlen)); |
831 | #endif | 846 | #endif |
@@ -889,7 +904,7 @@ receive_again (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
889 | GNUNET_TIME_absolute_get_remaining | 904 | GNUNET_TIME_absolute_get_remaining |
890 | (sh->receive_timeout), | 905 | (sh->receive_timeout), |
891 | sh->sock, &receive_ready, | 906 | sh->sock, &receive_ready, |
892 | sh); | 907 | sh); |
893 | } | 908 | } |
894 | 909 | ||
895 | 910 | ||
@@ -1086,7 +1101,14 @@ transmit_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1086 | RETRY: | 1101 | RETRY: |
1087 | ret = SEND (sock->sock, | 1102 | ret = SEND (sock->sock, |
1088 | &sock->write_buffer[sock->write_buffer_pos], | 1103 | &sock->write_buffer[sock->write_buffer_pos], |
1089 | have, MSG_DONTWAIT | MSG_NOSIGNAL); | 1104 | have, |
1105 | #ifndef MINGW | ||
1106 | // FIXME NILS | ||
1107 | MSG_DONTWAIT | MSG_NOSIGNAL | ||
1108 | #else | ||
1109 | 0 | ||
1110 | #endif | ||
1111 | ); | ||
1090 | if (ret == -1) | 1112 | if (ret == -1) |
1091 | { | 1113 | { |
1092 | if (errno == EINTR) | 1114 | if (errno == EINTR) |
diff --git a/src/util/os_priority.c b/src/util/os_priority.c index 7862d68e9..f74bd9266 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c | |||
@@ -123,9 +123,11 @@ GNUNET_OS_set_process_priority (pid_t proc, | |||
123 | pid_t | 123 | pid_t |
124 | GNUNET_OS_start_process (const char *filename, ...) | 124 | GNUNET_OS_start_process (const char *filename, ...) |
125 | { | 125 | { |
126 | va_list ap; | ||
127 | |||
128 | #ifndef MINGW | ||
126 | pid_t ret; | 129 | pid_t ret; |
127 | char **argv; | 130 | char **argv; |
128 | va_list ap; | ||
129 | int argc; | 131 | int argc; |
130 | 132 | ||
131 | ret = fork (); | 133 | ret = fork (); |
@@ -149,6 +151,42 @@ GNUNET_OS_start_process (const char *filename, ...) | |||
149 | execvp (filename, argv); | 151 | execvp (filename, argv); |
150 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); | 152 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); |
151 | exit (1); | 153 | exit (1); |
154 | #else | ||
155 | char *arg; | ||
156 | unsigned int cmdlen; | ||
157 | char *cmd, *idx; | ||
158 | STARTUPINFO start; | ||
159 | PROCESS_INFORMATION proc; | ||
160 | |||
161 | cmdlen = 0; | ||
162 | va_start (ap, filename); | ||
163 | while (NULL != (arg = va_arg (ap, char *))) | ||
164 | cmdlen = cmdlen + strlen (arg) + 3; | ||
165 | va_end (ap); | ||
166 | |||
167 | cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); | ||
168 | va_start (ap, filename); | ||
169 | while (NULL != (arg = va_arg (ap, char *))) | ||
170 | idx += sprintf (idx, "\"%s\" ", arg); | ||
171 | va_end (ap); | ||
172 | |||
173 | memset (&start, 0, sizeof(start)); | ||
174 | start.cb = sizeof(start); | ||
175 | |||
176 | if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, | ||
177 | NULL, &start, &proc)) | ||
178 | { | ||
179 | SetErrnoFromWinError (GetLastError ()); | ||
180 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); | ||
181 | return -1; | ||
182 | } | ||
183 | CloseHandle (proc.hProcess); | ||
184 | CloseHandle (proc.hThread); | ||
185 | |||
186 | GNUNET_free(cmd); | ||
187 | |||
188 | return proc.dwProcessId; | ||
189 | #endif | ||
152 | } | 190 | } |
153 | 191 | ||
154 | 192 | ||
@@ -164,6 +202,7 @@ GNUNET_OS_start_process (const char *filename, ...) | |||
164 | pid_t | 202 | pid_t |
165 | GNUNET_OS_start_process_v (const char *filename, char *const argv[]) | 203 | GNUNET_OS_start_process_v (const char *filename, char *const argv[]) |
166 | { | 204 | { |
205 | #ifndef MINGW | ||
167 | pid_t ret; | 206 | pid_t ret; |
168 | 207 | ||
169 | ret = fork (); | 208 | ret = fork (); |
@@ -176,6 +215,46 @@ GNUNET_OS_start_process_v (const char *filename, char *const argv[]) | |||
176 | execvp (filename, argv); | 215 | execvp (filename, argv); |
177 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); | 216 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "execvp", filename); |
178 | exit (1); | 217 | exit (1); |
218 | #else | ||
219 | char **arg; | ||
220 | unsigned int cmdlen; | ||
221 | char *cmd, *idx; | ||
222 | STARTUPINFO start; | ||
223 | PROCESS_INFORMATION proc; | ||
224 | |||
225 | cmdlen = 0; | ||
226 | arg = argv; | ||
227 | while (*arg) | ||
228 | { | ||
229 | cmdlen = cmdlen + strlen (*arg) + 3; | ||
230 | arg++; | ||
231 | } | ||
232 | |||
233 | cmd = idx = GNUNET_malloc (sizeof(char) * cmdlen); | ||
234 | arg = argv; | ||
235 | while (*arg) | ||
236 | { | ||
237 | idx += sprintf (idx, "\"%s\" ", *arg); | ||
238 | arg++; | ||
239 | } | ||
240 | |||
241 | memset (&start, 0, sizeof(start)); | ||
242 | start.cb = sizeof(start); | ||
243 | |||
244 | if (!CreateProcess (filename, cmd, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, | ||
245 | NULL, &start, &proc)) | ||
246 | { | ||
247 | SetErrnoFromWinError (GetLastError ()); | ||
248 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "fork"); | ||
249 | return -1; | ||
250 | } | ||
251 | CloseHandle (proc.hProcess); | ||
252 | CloseHandle (proc.hThread); | ||
253 | |||
254 | GNUNET_free(cmd); | ||
255 | |||
256 | return proc.dwProcessId; | ||
257 | #endif | ||
179 | } | 258 | } |
180 | 259 | ||
181 | 260 | ||
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index a20b3da06..4872eee41 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -470,10 +470,12 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_Task task, void *cls) | |||
470 | struct Task *tpos; | 470 | struct Task *tpos; |
471 | 471 | ||
472 | sig_shutdown = 0; | 472 | sig_shutdown = 0; |
473 | #ifndef MINGW | ||
473 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); | 474 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, &sighandler_shutdown); |
474 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); | 475 | shc_term = GNUNET_SIGNAL_handler_install (SIGTERM, &sighandler_shutdown); |
475 | shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); | 476 | shc_quit = GNUNET_SIGNAL_handler_install (SIGQUIT, &sighandler_shutdown); |
476 | shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); | 477 | shc_hup = GNUNET_SIGNAL_handler_install (SIGHUP, &sighandler_shutdown); |
478 | #endif | ||
477 | memset (&sched, 0, sizeof (sched)); | 479 | memset (&sched, 0, sizeof (sched)); |
478 | sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | 480 | sched.current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; |
479 | GNUNET_SCHEDULER_add_continuation (&sched, | 481 | GNUNET_SCHEDULER_add_continuation (&sched, |
diff --git a/src/util/server.c b/src/util/server.c index 939814725..282e036e8 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -379,9 +379,12 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
379 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 379 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
380 | return -1; | 380 | return -1; |
381 | } | 381 | } |
382 | #ifndef MINGW | ||
383 | // FIXME NILS | ||
382 | if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC)) | 384 | if (0 != fcntl (fd, F_SETFD, fcntl (fd, F_GETFD) | FD_CLOEXEC)) |
383 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 385 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
384 | "fcntl"); | 386 | "fcntl"); |
387 | #endif | ||
385 | if (SETSOCKOPT (fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) | 388 | if (SETSOCKOPT (fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0) |
386 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 389 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
387 | "setsockopt"); | 390 | "setsockopt"); |
diff --git a/src/util/time.c b/src/util/time.c index 3ae472561..c8f408841 100644 --- a/src/util/time.c +++ b/src/util/time.c | |||
@@ -39,7 +39,7 @@ GNUNET_TIME_absolute_get () | |||
39 | struct GNUNET_TIME_Absolute ret; | 39 | struct GNUNET_TIME_Absolute ret; |
40 | struct timeval tv; | 40 | struct timeval tv; |
41 | 41 | ||
42 | gettimeofday (&tv, NULL); | 42 | GETTIMEOFDAY (&tv, NULL); |
43 | ret.value = tv.tv_sec * 1000 + tv.tv_usec / 1000; | 43 | ret.value = tv.tv_sec * 1000 + tv.tv_usec / 1000; |
44 | return ret; | 44 | return ret; |
45 | } | 45 | } |
diff --git a/src/util/win.cc b/src/util/win.cc new file mode 100644 index 000000000..f3e4bd98c --- /dev/null +++ b/src/util/win.cc | |||
@@ -0,0 +1,828 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/win/win.cc | ||
23 | * @brief Helper functions for MS Windows in C++ | ||
24 | * @author Nils Durner | ||
25 | **/ | ||
26 | |||
27 | #ifndef _WIN_CC | ||
28 | #define _WIN_CC | ||
29 | |||
30 | #include "winproc.h" | ||
31 | #include "platform.h" | ||
32 | #include "gnunet_common.h" | ||
33 | #include "gnunet_network_lib.h" | ||
34 | |||
35 | #include <list> | ||
36 | using namespace std; | ||
37 | #include <ntdef.h> | ||
38 | |||
39 | #ifndef INHERITED_ACE | ||
40 | #define INHERITED_ACE 0x10 | ||
41 | #endif | ||
42 | |||
43 | extern "C" { | ||
44 | |||
45 | typedef list<WSAOVERLAPPED *> TOLList; | ||
46 | |||
47 | static HANDLE hOLLock; | ||
48 | static TOLList lstOL; | ||
49 | |||
50 | int plibc_conv_to_win_path(const char *pszUnix, char *pszWindows); | ||
51 | |||
52 | void __attribute__ ((constructor)) gnunet_win_init() { | ||
53 | hOLLock = CreateMutex(NULL, FALSE, NULL); | ||
54 | } | ||
55 | |||
56 | void __attribute__ ((destructor)) gnunet_win_fini() { | ||
57 | CloseHandle(hOLLock); | ||
58 | } | ||
59 | |||
60 | /** | ||
61 | * Enumerate all network adapters | ||
62 | */ | ||
63 | void EnumNICs(PMIB_IFTABLE *pIfTable, PMIB_IPADDRTABLE *pAddrTable) | ||
64 | { | ||
65 | DWORD dwSize, dwRet; | ||
66 | |||
67 | *pIfTable = NULL; | ||
68 | |||
69 | if (pAddrTable) | ||
70 | *pAddrTable = NULL; | ||
71 | |||
72 | if (GNGetIfTable) | ||
73 | { | ||
74 | dwSize = dwRet = 0; | ||
75 | |||
76 | *pIfTable = (MIB_IFTABLE *) GlobalAlloc(GPTR, sizeof(MIB_IFTABLE)); | ||
77 | |||
78 | /* Get size of table */ | ||
79 | if (GNGetIfTable(*pIfTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) | ||
80 | { | ||
81 | GlobalFree(*pIfTable); | ||
82 | *pIfTable = (MIB_IFTABLE *) GlobalAlloc(GPTR, dwSize); | ||
83 | } | ||
84 | |||
85 | if ((dwRet = GNGetIfTable(*pIfTable, &dwSize, 0)) == NO_ERROR && | ||
86 | pAddrTable) | ||
87 | { | ||
88 | DWORD dwIfIdx, dwSize = sizeof(MIB_IPADDRTABLE); | ||
89 | *pAddrTable = (MIB_IPADDRTABLE *) GlobalAlloc(GPTR, dwSize); | ||
90 | |||
91 | /* Make an initial call to GetIpAddrTable to get the | ||
92 | necessary size */ | ||
93 | if (GNGetIpAddrTable(*pAddrTable, &dwSize, 0) == ERROR_INSUFFICIENT_BUFFER) | ||
94 | { | ||
95 | GlobalFree(*pAddrTable); | ||
96 | *pAddrTable = (MIB_IPADDRTABLE *) GlobalAlloc(GPTR, dwSize); | ||
97 | } | ||
98 | GNGetIpAddrTable(*pAddrTable, &dwSize, 0); | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * Lists all network interfaces in a combo box | ||
105 | * Used by the basic GTK configurator | ||
106 | * @param callback | ||
107 | */ | ||
108 | int ListNICs(void (*callback) (const char *, int, void *), void * cls) | ||
109 | { | ||
110 | PMIB_IFTABLE pTable; | ||
111 | PMIB_IPADDRTABLE pAddrTable; | ||
112 | DWORD dwIfIdx, dwExternalNIC; | ||
113 | IPAddr theIP; | ||
114 | |||
115 | /* Determine our external NIC */ | ||
116 | theIP = inet_addr("192.0.34.166"); /* www.example.com */ | ||
117 | if ((! GNGetBestInterface) || | ||
118 | (GNGetBestInterface(theIP, &dwExternalNIC) != NO_ERROR)) | ||
119 | { | ||
120 | dwExternalNIC = 0; | ||
121 | } | ||
122 | |||
123 | /* Enumerate NICs */ | ||
124 | EnumNICs(&pTable, &pAddrTable); | ||
125 | |||
126 | if (pTable) | ||
127 | { | ||
128 | for(dwIfIdx=0; dwIfIdx <= pTable->dwNumEntries; dwIfIdx++) | ||
129 | { | ||
130 | char szEntry[1001]; | ||
131 | DWORD dwIP = 0; | ||
132 | int iItm; | ||
133 | PIP_ADAPTER_INFO pAdapterInfo; | ||
134 | PIP_ADAPTER_INFO pAdapter = NULL; | ||
135 | DWORD dwRetVal = 0; | ||
136 | |||
137 | /* Get IP-Address */ | ||
138 | int i; | ||
139 | for(i = 0; i < pAddrTable->dwNumEntries; i++) | ||
140 | { | ||
141 | if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) | ||
142 | { | ||
143 | dwIP = pAddrTable->table[i].dwAddr; | ||
144 | break; | ||
145 | } | ||
146 | } | ||
147 | |||
148 | if (dwIP) | ||
149 | { | ||
150 | BYTE bPhysAddr[MAXLEN_PHYSADDR]; | ||
151 | char *pszIfName = NULL; | ||
152 | char dst[INET_ADDRSTRLEN]; | ||
153 | |||
154 | /* Get friendly interface name */ | ||
155 | pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO)); | ||
156 | ULONG ulOutBufLen = sizeof(IP_ADAPTER_INFO); | ||
157 | |||
158 | /* Make an initial call to GetAdaptersInfo to get | ||
159 | the necessary size into the ulOutBufLen variable */ | ||
160 | if (GGetAdaptersInfo(pAdapterInfo, &ulOutBufLen) == ERROR_BUFFER_OVERFLOW) { | ||
161 | free(pAdapterInfo); | ||
162 | pAdapterInfo = (IP_ADAPTER_INFO *) malloc (ulOutBufLen); | ||
163 | } | ||
164 | |||
165 | if ((dwRetVal = GGetAdaptersInfo( pAdapterInfo, &ulOutBufLen)) == NO_ERROR) { | ||
166 | pAdapter = pAdapterInfo; | ||
167 | while (pAdapter) { | ||
168 | if (pTable->table[dwIfIdx].dwIndex == pAdapter->Index) | ||
169 | { | ||
170 | char szKey[251]; | ||
171 | long lLen = 250; | ||
172 | |||
173 | sprintf(szKey, "SYSTEM\\CurrentControlSet\\Control\\Network\\" | ||
174 | "{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", | ||
175 | pAdapter->AdapterName); | ||
176 | pszIfName = (char *) malloc(251); | ||
177 | if (QueryRegistry(HKEY_LOCAL_MACHINE, szKey, "Name", pszIfName, | ||
178 | &lLen) != ERROR_SUCCESS) | ||
179 | { | ||
180 | free(pszIfName); | ||
181 | pszIfName = NULL; | ||
182 | } | ||
183 | } | ||
184 | pAdapter = pAdapter->Next; | ||
185 | } | ||
186 | } | ||
187 | free(pAdapterInfo); | ||
188 | |||
189 | /* Set entry */ | ||
190 | memset(bPhysAddr, 0, MAXLEN_PHYSADDR); | ||
191 | memcpy(bPhysAddr, | ||
192 | pTable->table[dwIfIdx].bPhysAddr, | ||
193 | pTable->table[dwIfIdx].dwPhysAddrLen); | ||
194 | |||
195 | snprintf(szEntry, 1000, "%s (%s - %I64u)", | ||
196 | pszIfName ? pszIfName : (char *) pTable->table[dwIfIdx].bDescr, | ||
197 | inet_ntop (AF_INET, &dwIP, dst, INET_ADDRSTRLEN), | ||
198 | *((unsigned long long *) bPhysAddr)); | ||
199 | szEntry[1000] = 0; | ||
200 | |||
201 | if (pszIfName) | ||
202 | free(pszIfName); | ||
203 | |||
204 | callback(szEntry, pAddrTable->table[dwIfIdx].dwIndex == dwExternalNIC, cls); | ||
205 | } | ||
206 | } | ||
207 | GlobalFree(pAddrTable); | ||
208 | GlobalFree(pTable); | ||
209 | } | ||
210 | |||
211 | return GNUNET_YES; | ||
212 | } | ||
213 | |||
214 | /** | ||
215 | * @brief Installs the Windows service | ||
216 | * @param servicename name of the service as diplayed by the SCM | ||
217 | * @param application path to the application binary | ||
218 | * @param username the name of the service's user account | ||
219 | * @returns 0 on success | ||
220 | * 1 if the Windows version doesn't support services | ||
221 | * 2 if the SCM could not be opened | ||
222 | * 3 if the service could not be created | ||
223 | */ | ||
224 | int InstallAsService(char *servicename, char *application, char *username) | ||
225 | { | ||
226 | SC_HANDLE hManager, hService; | ||
227 | char szEXE[_MAX_PATH + 17] = "\""; | ||
228 | char *user = NULL; | ||
229 | |||
230 | if (! GNOpenSCManager) | ||
231 | return 1; | ||
232 | |||
233 | plibc_conv_to_win_path(application, szEXE + 1); | ||
234 | strcat(szEXE, "\" --win-service"); | ||
235 | hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CREATE_SERVICE); | ||
236 | if (! hManager) | ||
237 | return 2; | ||
238 | |||
239 | if (username) | ||
240 | { | ||
241 | user = (char *) malloc(strlen(username) + 3); | ||
242 | sprintf(user, ".\\%s", username); | ||
243 | } | ||
244 | |||
245 | hService = GNCreateService(hManager, (LPCTSTR) servicename, (LPCTSTR) servicename, 0, | ||
246 | SERVICE_WIN32_OWN_PROCESS, SERVICE_AUTO_START, SERVICE_ERROR_NORMAL, (LPCTSTR) szEXE, | ||
247 | NULL, NULL, NULL, (LPCTSTR) user, (LPCTSTR) username); | ||
248 | |||
249 | if (user) | ||
250 | free(user); | ||
251 | |||
252 | if (! hService) | ||
253 | return 3; | ||
254 | |||
255 | GNCloseServiceHandle(hService); | ||
256 | |||
257 | return 0; | ||
258 | } | ||
259 | |||
260 | /** | ||
261 | * @brief Uninstall Windows service | ||
262 | * @param servicename name of the service to delete | ||
263 | * @returns 0 on success | ||
264 | * 1 if the Windows version doesn't support services | ||
265 | * 2 if the SCM could not be openend | ||
266 | * 3 if the service cannot be accessed | ||
267 | * 4 if the service cannot be deleted | ||
268 | */ | ||
269 | int UninstallService(char *servicename) | ||
270 | { | ||
271 | SC_HANDLE hManager, hService; | ||
272 | |||
273 | if (! GNOpenSCManager) | ||
274 | return 1; | ||
275 | |||
276 | hManager = GNOpenSCManager(NULL, NULL, SC_MANAGER_CONNECT); | ||
277 | if (! hManager) | ||
278 | return 2; | ||
279 | |||
280 | if (! (hService = GNOpenService(hManager, (LPCTSTR) servicename, DELETE))) | ||
281 | if (GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) | ||
282 | return 3; | ||
283 | else | ||
284 | goto closeSCM; | ||
285 | |||
286 | if (! GNDeleteService(hService)) | ||
287 | if (GetLastError() != ERROR_SERVICE_MARKED_FOR_DELETE) | ||
288 | return 4; | ||
289 | |||
290 | closeSCM: | ||
291 | GNCloseServiceHandle(hService); | ||
292 | |||
293 | return 0; | ||
294 | } | ||
295 | |||
296 | /** | ||
297 | * @author Scott Field, Microsoft | ||
298 | * @see http://support.microsoft.com/?scid=kb;en-us;132958 | ||
299 | * @date 12-Jul-95 | ||
300 | */ | ||
301 | void _InitLsaString(PLSA_UNICODE_STRING LsaString, LPWSTR String) | ||
302 | { | ||
303 | DWORD StringLength; | ||
304 | |||
305 | if(String == NULL) | ||
306 | { | ||
307 | LsaString->Buffer = NULL; | ||
308 | LsaString->Length = 0; | ||
309 | LsaString->MaximumLength = 0; | ||
310 | return; | ||
311 | } | ||
312 | |||
313 | StringLength = wcslen(String); | ||
314 | LsaString->Buffer = String; | ||
315 | LsaString->Length = (USHORT) StringLength *sizeof(WCHAR); | ||
316 | LsaString->MaximumLength = (USHORT) (StringLength + 1) * sizeof(WCHAR); | ||
317 | } | ||
318 | |||
319 | |||
320 | /** | ||
321 | * @author Scott Field, Microsoft | ||
322 | * @see http://support.microsoft.com/?scid=kb;en-us;132958 | ||
323 | * @date 12-Jul-95 | ||
324 | */ | ||
325 | NTSTATUS _OpenPolicy(LPWSTR ServerName, DWORD DesiredAccess, PLSA_HANDLE PolicyHandle) | ||
326 | { | ||
327 | LSA_OBJECT_ATTRIBUTES ObjectAttributes; | ||
328 | LSA_UNICODE_STRING ServerString; | ||
329 | PLSA_UNICODE_STRING Server = NULL; | ||
330 | |||
331 | /* Always initialize the object attributes to all zeroes. */ | ||
332 | ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes)); | ||
333 | |||
334 | if(ServerName != NULL) | ||
335 | { | ||
336 | /* Make a LSA_UNICODE_STRING out of the LPWSTR passed in */ | ||
337 | _InitLsaString(&ServerString, ServerName); | ||
338 | Server = &ServerString; | ||
339 | } | ||
340 | |||
341 | /* Attempt to open the policy. */ | ||
342 | return GNLsaOpenPolicy(Server, | ||
343 | &ObjectAttributes, DesiredAccess, PolicyHandle); | ||
344 | } | ||
345 | |||
346 | /** | ||
347 | * @brief Obtain a SID representing the supplied account on the supplied system | ||
348 | * @return TRUE on success, FALSE on failure | ||
349 | * @author Scott Field, Microsoft | ||
350 | * @date 12-Jul-95 | ||
351 | * @remarks A buffer is allocated which contains the SID representing the | ||
352 | * supplied account. This buffer should be freed when it is no longer | ||
353 | * needed by calling\n | ||
354 | * HeapFree(GetProcessHeap(), 0, buffer) | ||
355 | * @remarks Call GetLastError() to obtain extended error information. | ||
356 | * @see http://support.microsoft.com/?scid=kb;en-us;132958 | ||
357 | */ | ||
358 | BOOL _GetAccountSid(LPTSTR SystemName, LPTSTR AccountName, PSID * Sid) | ||
359 | { | ||
360 | LPTSTR ReferencedDomain = NULL; | ||
361 | DWORD cbSid = 128; /* initial allocation attempt */ | ||
362 | DWORD cchReferencedDomain = 16; /* initial allocation size */ | ||
363 | SID_NAME_USE peUse; | ||
364 | BOOL bSuccess = FALSE; /* assume this function will fail */ | ||
365 | |||
366 | /* initial memory allocations */ | ||
367 | if ((*Sid = HeapAlloc (GetProcessHeap (), 0, cbSid)) == NULL) | ||
368 | return FALSE; | ||
369 | |||
370 | if ((ReferencedDomain = (LPTSTR) HeapAlloc (GetProcessHeap (), | ||
371 | 0, | ||
372 | cchReferencedDomain * | ||
373 | sizeof (TCHAR))) == NULL) | ||
374 | return FALSE; | ||
375 | |||
376 | /* Obtain the SID of the specified account on the specified system. */ | ||
377 | while (!GNLookupAccountName(SystemName, /* machine to lookup account on */ | ||
378 | AccountName, /* account to lookup */ | ||
379 | *Sid, /* SID of interest */ | ||
380 | &cbSid, /* size of SID */ | ||
381 | ReferencedDomain, /* domain account was found on */ | ||
382 | &cchReferencedDomain, &peUse)) | ||
383 | { | ||
384 | if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) | ||
385 | { | ||
386 | /* reallocate memory */ | ||
387 | if ((*Sid = HeapReAlloc (GetProcessHeap (), 0, *Sid, cbSid)) == NULL) | ||
388 | return FALSE; | ||
389 | |||
390 | if ((ReferencedDomain = (LPTSTR) HeapReAlloc (GetProcessHeap (), | ||
391 | 0, | ||
392 | ReferencedDomain, | ||
393 | cchReferencedDomain | ||
394 | * sizeof (TCHAR))) == NULL) | ||
395 | return FALSE; | ||
396 | } | ||
397 | else | ||
398 | goto end; | ||
399 | } | ||
400 | |||
401 | /* Indicate success. */ | ||
402 | bSuccess = TRUE; | ||
403 | |||
404 | end: | ||
405 | /* Cleanup and indicate failure, if appropriate. */ | ||
406 | HeapFree (GetProcessHeap (), 0, ReferencedDomain); | ||
407 | |||
408 | if (!bSuccess) | ||
409 | { | ||
410 | if (*Sid != NULL) | ||
411 | { | ||
412 | HeapFree (GetProcessHeap (), 0, *Sid); | ||
413 | *Sid = NULL; | ||
414 | } | ||
415 | } | ||
416 | |||
417 | return bSuccess; | ||
418 | } | ||
419 | |||
420 | /** | ||
421 | * @author Scott Field, Microsoft | ||
422 | * @see http://support.microsoft.com/?scid=kb;en-us;132958 | ||
423 | * @date 12-Jul-95 | ||
424 | */ | ||
425 | NTSTATUS _SetPrivilegeOnAccount(LSA_HANDLE PolicyHandle,/* open policy handle */ | ||
426 | PSID AccountSid, /* SID to grant privilege to */ | ||
427 | LPWSTR PrivilegeName, /* privilege to grant (Unicode) */ | ||
428 | BOOL bEnable /* enable or disable */ | ||
429 | ) | ||
430 | { | ||
431 | LSA_UNICODE_STRING PrivilegeString; | ||
432 | |||
433 | /* Create a LSA_UNICODE_STRING for the privilege name. */ | ||
434 | _InitLsaString(&PrivilegeString, PrivilegeName); | ||
435 | |||
436 | /* grant or revoke the privilege, accordingly */ | ||
437 | if(bEnable) | ||
438 | { | ||
439 | NTSTATUS i; | ||
440 | |||
441 | i = GNLsaAddAccountRights(PolicyHandle, /* open policy handle */ | ||
442 | AccountSid, /* target SID */ | ||
443 | &PrivilegeString, /* privileges */ | ||
444 | 1 /* privilege count */ | ||
445 | ); | ||
446 | } | ||
447 | else | ||
448 | { | ||
449 | return GNLsaRemoveAccountRights(PolicyHandle, /* open policy handle */ | ||
450 | AccountSid, /* target SID */ | ||
451 | FALSE, /* do not disable all rights */ | ||
452 | &PrivilegeString, /* privileges */ | ||
453 | 1 /* privilege count */ | ||
454 | ); | ||
455 | } | ||
456 | } | ||
457 | |||
458 | /** | ||
459 | * @brief Create a Windows service account | ||
460 | * @return 0 on success, > 0 otherwise | ||
461 | * @param pszName the name of the account | ||
462 | * @param pszDesc description of the account | ||
463 | */ | ||
464 | int CreateServiceAccount(char *pszName, char *pszDesc) | ||
465 | { | ||
466 | USER_INFO_1 ui; | ||
467 | USER_INFO_1008 ui2; | ||
468 | NET_API_STATUS nStatus; | ||
469 | wchar_t wszName[MAX_NAME_LENGTH], wszDesc[MAX_NAME_LENGTH]; | ||
470 | DWORD dwErr; | ||
471 | LSA_HANDLE hPolicy; | ||
472 | PSID pSID; | ||
473 | |||
474 | if (! GNNetUserAdd) | ||
475 | return 1; | ||
476 | mbstowcs(wszName, pszName, strlen(pszName) + 1); | ||
477 | mbstowcs(wszDesc, pszDesc, strlen(pszDesc) + 1); | ||
478 | |||
479 | memset(&ui, 0, sizeof(ui)); | ||
480 | ui.usri1_name = wszName; | ||
481 | ui.usri1_password = wszName; /* account is locked anyway */ | ||
482 | ui.usri1_priv = USER_PRIV_USER; | ||
483 | ui.usri1_comment = wszDesc; | ||
484 | ui.usri1_flags = UF_SCRIPT; | ||
485 | |||
486 | nStatus = GNNetUserAdd(NULL, 1, (LPBYTE)&ui, NULL); | ||
487 | |||
488 | if (nStatus != NERR_Success && nStatus != NERR_UserExists) | ||
489 | return 2; | ||
490 | |||
491 | ui2.usri1008_flags = UF_PASSWD_CANT_CHANGE | UF_DONT_EXPIRE_PASSWD; | ||
492 | GNNetUserSetInfo(NULL, wszName, 1008, (LPBYTE)&ui2, NULL); | ||
493 | |||
494 | if (_OpenPolicy(NULL, POLICY_ALL_ACCESS, &hPolicy) != | ||
495 | STATUS_SUCCESS) | ||
496 | return 3; | ||
497 | |||
498 | _GetAccountSid(NULL, (LPTSTR) pszName, &pSID); | ||
499 | |||
500 | if (_SetPrivilegeOnAccount(hPolicy, pSID, L"SeServiceLogonRight", TRUE) != STATUS_SUCCESS) | ||
501 | return 4; | ||
502 | |||
503 | _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyInteractiveLogonRight", TRUE); | ||
504 | _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyBatchLogonRight", TRUE); | ||
505 | _SetPrivilegeOnAccount(hPolicy, pSID, L"SeDenyNetworkLogonRight", TRUE); | ||
506 | |||
507 | GNLsaClose(hPolicy); | ||
508 | |||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | /** | ||
513 | * @brief Grant permission to a file | ||
514 | * @param lpszFileName the name of the file or directory | ||
515 | * @param lpszAccountName the user account | ||
516 | * @param the desired access (e.g. GENERIC_ALL) | ||
517 | * @return TRUE on success | ||
518 | * @remark based on http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q102102& | ||
519 | */ | ||
520 | BOOL AddPathAccessRights(char *lpszFileName, char *lpszAccountName, | ||
521 | DWORD dwAccessMask) | ||
522 | { | ||
523 | /* SID variables. */ | ||
524 | SID_NAME_USE snuType; | ||
525 | TCHAR * szDomain = NULL; | ||
526 | DWORD cbDomain = 0; | ||
527 | LPVOID pUserSID = NULL; | ||
528 | DWORD cbUserSID = 0; | ||
529 | |||
530 | /* File SD variables. */ | ||
531 | PSECURITY_DESCRIPTOR pFileSD = NULL; | ||
532 | DWORD cbFileSD = 0; | ||
533 | |||
534 | /* New SD variables. */ | ||
535 | SECURITY_DESCRIPTOR newSD; | ||
536 | |||
537 | /* ACL variables. */ | ||
538 | PACL pACL = NULL; | ||
539 | BOOL fDaclPresent; | ||
540 | BOOL fDaclDefaulted; | ||
541 | ACL_SIZE_INFORMATION AclInfo; | ||
542 | |||
543 | /* New ACL variables. */ | ||
544 | PACL pNewACL = NULL; | ||
545 | DWORD cbNewACL = 0; | ||
546 | |||
547 | /* Temporary ACE. */ | ||
548 | LPVOID pTempAce = NULL; | ||
549 | UINT CurrentAceIndex = 0; | ||
550 | |||
551 | UINT newAceIndex = 0; | ||
552 | |||
553 | /* Assume function will fail. */ | ||
554 | BOOL fResult = FALSE; | ||
555 | BOOL fAPISuccess; | ||
556 | |||
557 | SECURITY_INFORMATION secInfo = DACL_SECURITY_INFORMATION; | ||
558 | |||
559 | /** | ||
560 | * STEP 1: Get SID of the account name specified. | ||
561 | */ | ||
562 | fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR) lpszAccountName, | ||
563 | pUserSID, &cbUserSID, (LPTSTR) szDomain, &cbDomain, &snuType); | ||
564 | |||
565 | /* API should have failed with insufficient buffer. */ | ||
566 | if (fAPISuccess) | ||
567 | goto end; | ||
568 | else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | ||
569 | goto end; | ||
570 | } | ||
571 | |||
572 | pUserSID = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbUserSID); | ||
573 | if (!pUserSID) { | ||
574 | goto end; | ||
575 | } | ||
576 | |||
577 | szDomain = (TCHAR *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbDomain * sizeof(TCHAR)); | ||
578 | if (!szDomain) { | ||
579 | goto end; | ||
580 | } | ||
581 | |||
582 | fAPISuccess = GNLookupAccountName(NULL, (LPCTSTR) lpszAccountName, | ||
583 | pUserSID, &cbUserSID, (LPTSTR) szDomain, &cbDomain, &snuType); | ||
584 | if (!fAPISuccess) { | ||
585 | goto end; | ||
586 | } | ||
587 | |||
588 | /** | ||
589 | * STEP 2: Get security descriptor (SD) of the file specified. | ||
590 | */ | ||
591 | fAPISuccess = GNGetFileSecurity((LPCTSTR) lpszFileName, | ||
592 | secInfo, pFileSD, 0, &cbFileSD); | ||
593 | |||
594 | /* API should have failed with insufficient buffer. */ | ||
595 | if (fAPISuccess) | ||
596 | goto end; | ||
597 | else if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) { | ||
598 | goto end; | ||
599 | } | ||
600 | |||
601 | pFileSD = (PSECURITY_DESCRIPTOR) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, | ||
602 | cbFileSD); | ||
603 | if (!pFileSD) { | ||
604 | goto end; | ||
605 | } | ||
606 | |||
607 | fAPISuccess = GNGetFileSecurity((LPCTSTR) lpszFileName, | ||
608 | secInfo, pFileSD, cbFileSD, &cbFileSD); | ||
609 | if (!fAPISuccess) { | ||
610 | goto end; | ||
611 | } | ||
612 | |||
613 | /** | ||
614 | * STEP 3: Initialize new SD. | ||
615 | */ | ||
616 | if (!GNInitializeSecurityDescriptor(&newSD, | ||
617 | SECURITY_DESCRIPTOR_REVISION)) { | ||
618 | goto end; | ||
619 | } | ||
620 | |||
621 | /** | ||
622 | * STEP 4: Get DACL from the old SD. | ||
623 | */ | ||
624 | if (!GNGetSecurityDescriptorDacl(pFileSD, &fDaclPresent, &pACL, | ||
625 | &fDaclDefaulted)) { | ||
626 | goto end; | ||
627 | } | ||
628 | |||
629 | /** | ||
630 | * STEP 5: Get size information for DACL. | ||
631 | */ | ||
632 | AclInfo.AceCount = 0; // Assume NULL DACL. | ||
633 | AclInfo.AclBytesFree = 0; | ||
634 | AclInfo.AclBytesInUse = sizeof(ACL); | ||
635 | |||
636 | if (pACL == NULL) | ||
637 | fDaclPresent = FALSE; | ||
638 | |||
639 | /* If not NULL DACL, gather size information from DACL. */ | ||
640 | if (fDaclPresent) { | ||
641 | |||
642 | if (!GNGetAclInformation(pACL, &AclInfo, | ||
643 | sizeof(ACL_SIZE_INFORMATION), AclSizeInformation)) { | ||
644 | goto end; | ||
645 | } | ||
646 | } | ||
647 | |||
648 | /** | ||
649 | * STEP 6: Compute size needed for the new ACL. | ||
650 | */ | ||
651 | cbNewACL = AclInfo.AclBytesInUse + sizeof(ACCESS_ALLOWED_ACE) | ||
652 | + GetLengthSid(pUserSID) - sizeof(DWORD); | ||
653 | |||
654 | /** | ||
655 | * STEP 7: Allocate memory for new ACL. | ||
656 | */ | ||
657 | pNewACL = (PACL) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbNewACL); | ||
658 | if (!pNewACL) { | ||
659 | goto end; | ||
660 | } | ||
661 | |||
662 | /** | ||
663 | * STEP 8: Initialize the new ACL. | ||
664 | */ | ||
665 | if (!GNInitializeAcl(pNewACL, cbNewACL, ACL_REVISION2)) { | ||
666 | goto end; | ||
667 | } | ||
668 | |||
669 | /** | ||
670 | * STEP 9 If DACL is present, copy all the ACEs from the old DACL | ||
671 | * to the new DACL. | ||
672 | * | ||
673 | * The following code assumes that the old DACL is | ||
674 | * already in Windows 2000 preferred order. To conform | ||
675 | * to the new Windows 2000 preferred order, first we will | ||
676 | * copy all non-inherited ACEs from the old DACL to the | ||
677 | * new DACL, irrespective of the ACE type. | ||
678 | */ | ||
679 | |||
680 | newAceIndex = 0; | ||
681 | |||
682 | if (fDaclPresent && AclInfo.AceCount) { | ||
683 | |||
684 | for (CurrentAceIndex = 0; | ||
685 | CurrentAceIndex < AclInfo.AceCount; | ||
686 | CurrentAceIndex++) { | ||
687 | |||
688 | /** | ||
689 | * TEP 10: Get an ACE. | ||
690 | */ | ||
691 | if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce)) { | ||
692 | goto end; | ||
693 | } | ||
694 | |||
695 | /** | ||
696 | * STEP 11: Check if it is a non-inherited ACE. | ||
697 | * If it is an inherited ACE, break from the loop so | ||
698 | * that the new access allowed non-inherited ACE can | ||
699 | * be added in the correct position, immediately after | ||
700 | * all non-inherited ACEs. | ||
701 | */ | ||
702 | if (((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags | ||
703 | & INHERITED_ACE) | ||
704 | break; | ||
705 | |||
706 | /** | ||
707 | * STEP 12: Skip adding the ACE, if the SID matches | ||
708 | * with the account specified, as we are going to | ||
709 | * add an access allowed ACE with a different access | ||
710 | * mask. | ||
711 | */ | ||
712 | if (GNEqualSid(pUserSID, | ||
713 | &(((ACCESS_ALLOWED_ACE *)pTempAce)->SidStart))) | ||
714 | continue; | ||
715 | |||
716 | /** | ||
717 | * STEP 13: Add the ACE to the new ACL. | ||
718 | */ | ||
719 | if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce, | ||
720 | ((PACE_HEADER) pTempAce)->AceSize)) { | ||
721 | goto end; | ||
722 | } | ||
723 | |||
724 | newAceIndex++; | ||
725 | } | ||
726 | } | ||
727 | |||
728 | /** | ||
729 | * STEP 14: Add the access-allowed ACE to the new DACL. | ||
730 | * The new ACE added here will be in the correct position, | ||
731 | * immediately after all existing non-inherited ACEs. | ||
732 | */ | ||
733 | if (!GNAddAccessAllowedAce(pNewACL, ACL_REVISION2, dwAccessMask, | ||
734 | pUserSID)) { | ||
735 | goto end; | ||
736 | } | ||
737 | |||
738 | /** | ||
739 | * STEP 14.5: Make new ACE inheritable | ||
740 | */ | ||
741 | if (!GetAce(pNewACL, newAceIndex, &pTempAce)) | ||
742 | goto end; | ||
743 | ((ACCESS_ALLOWED_ACE *)pTempAce)->Header.AceFlags |= | ||
744 | (CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE); | ||
745 | |||
746 | /** | ||
747 | * STEP 15: To conform to the new Windows 2000 preferred order, | ||
748 | * we will now copy the rest of inherited ACEs from the | ||
749 | * old DACL to the new DACL. | ||
750 | */ | ||
751 | if (fDaclPresent && AclInfo.AceCount) { | ||
752 | |||
753 | for (; | ||
754 | CurrentAceIndex < AclInfo.AceCount; | ||
755 | CurrentAceIndex++) { | ||
756 | |||
757 | /** | ||
758 | * STEP 16: Get an ACE. | ||
759 | */ | ||
760 | if (!GNGetAce(pACL, CurrentAceIndex, &pTempAce)) { | ||
761 | goto end; | ||
762 | } | ||
763 | |||
764 | /** | ||
765 | * STEP 17: Add the ACE to the new ACL. | ||
766 | */ | ||
767 | if (!GNAddAce(pNewACL, ACL_REVISION, MAXDWORD, pTempAce, | ||
768 | ((PACE_HEADER) pTempAce)->AceSize)) { | ||
769 | goto end; | ||
770 | } | ||
771 | } | ||
772 | } | ||
773 | |||
774 | /** | ||
775 | * STEP 18: Set permissions | ||
776 | */ | ||
777 | if (GNSetNamedSecurityInfo((LPTSTR) lpszFileName, SE_FILE_OBJECT, | ||
778 | DACL_SECURITY_INFORMATION, NULL, NULL, pNewACL, NULL) != ERROR_SUCCESS) { | ||
779 | goto end; | ||
780 | } | ||
781 | |||
782 | fResult = TRUE; | ||
783 | |||
784 | end: | ||
785 | |||
786 | /** | ||
787 | * STEP 19: Free allocated memory | ||
788 | */ | ||
789 | if (pUserSID) | ||
790 | HeapFree(GetProcessHeap(), 0, pUserSID); | ||
791 | |||
792 | if (szDomain) | ||
793 | HeapFree(GetProcessHeap(), 0, szDomain); | ||
794 | |||
795 | if (pFileSD) | ||
796 | HeapFree(GetProcessHeap(), 0, pFileSD); | ||
797 | |||
798 | if (pNewACL) | ||
799 | HeapFree(GetProcessHeap(), 0, pNewACL); | ||
800 | |||
801 | return fResult; | ||
802 | } | ||
803 | |||
804 | char *winErrorStr(const char *prefix, int dwErr) | ||
805 | { | ||
806 | char *err, *ret; | ||
807 | int mem; | ||
808 | |||
809 | if (! FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, | ||
810 | NULL, (DWORD) dwErr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &err, | ||
811 | 0, NULL )) | ||
812 | { | ||
813 | err = ""; | ||
814 | } | ||
815 | |||
816 | mem = strlen(err) + strlen(prefix) + 20; | ||
817 | ret = (char *) malloc(mem); | ||
818 | |||
819 | snprintf(ret, mem, "%s: %s (#%u)", prefix, err, dwErr); | ||
820 | |||
821 | LocalFree(err); | ||
822 | |||
823 | return ret; | ||
824 | } | ||
825 | |||
826 | } /* extern "C" */ | ||
827 | |||
828 | #endif | ||
diff --git a/src/util/winproc.c b/src/util/winproc.c new file mode 100644 index 000000000..469e1fb41 --- /dev/null +++ b/src/util/winproc.c | |||
@@ -0,0 +1,254 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other contributing authors) | ||
4 | |||
5 | GNUnet is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published | ||
7 | by the Free Software Foundation; either version 2, or (at your | ||
8 | option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with GNUnet; see the file COPYING. If not, write to the | ||
17 | Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
18 | Boston, MA 02111-1307, USA. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/win/winproc.c | ||
23 | * @brief Functions for MS Windows | ||
24 | * @author Nils Durner | ||
25 | */ | ||
26 | |||
27 | #include "platform.h" | ||
28 | #include "gnunet_common.h" | ||
29 | |||
30 | #define DEBUG_WINPROC 0 | ||
31 | |||
32 | #ifdef MINGW | ||
33 | |||
34 | static HINSTANCE hNTDLL, hIphlpapi, hAdvapi, hNetapi; | ||
35 | |||
36 | TNtQuerySystemInformation GNNtQuerySystemInformation; | ||
37 | TGetIfEntry GNGetIfEntry; | ||
38 | TGetIpAddrTable GNGetIpAddrTable; | ||
39 | TGetIfTable GNGetIfTable; | ||
40 | TOpenSCManager GNOpenSCManager; | ||
41 | TCreateService GNCreateService; | ||
42 | TCloseServiceHandle GNCloseServiceHandle; | ||
43 | TDeleteService GNDeleteService; | ||
44 | TRegisterServiceCtrlHandler GNRegisterServiceCtrlHandler; | ||
45 | TSetServiceStatus GNSetServiceStatus; | ||
46 | TStartServiceCtrlDispatcher GNStartServiceCtrlDispatcher; | ||
47 | TControlService GNControlService; | ||
48 | TOpenService GNOpenService; | ||
49 | TGetBestInterface GNGetBestInterface; | ||
50 | TGetAdaptersInfo GGetAdaptersInfo; | ||
51 | TNetUserAdd GNNetUserAdd; | ||
52 | TNetUserSetInfo GNNetUserSetInfo; | ||
53 | TLsaOpenPolicy GNLsaOpenPolicy; | ||
54 | TLsaAddAccountRights GNLsaAddAccountRights; | ||
55 | TLsaRemoveAccountRights GNLsaRemoveAccountRights; | ||
56 | TLsaClose GNLsaClose; | ||
57 | TLookupAccountName GNLookupAccountName; | ||
58 | TGetFileSecurity GNGetFileSecurity; | ||
59 | TInitializeSecurityDescriptor GNInitializeSecurityDescriptor; | ||
60 | TGetSecurityDescriptorDacl GNGetSecurityDescriptorDacl; | ||
61 | TGetAclInformation GNGetAclInformation; | ||
62 | TInitializeAcl GNInitializeAcl; | ||
63 | TGetAce GNGetAce; | ||
64 | TEqualSid GNEqualSid; | ||
65 | TAddAce GNAddAce; | ||
66 | TAddAccessAllowedAce GNAddAccessAllowedAce; | ||
67 | TSetNamedSecurityInfo GNSetNamedSecurityInfo; | ||
68 | |||
69 | /** | ||
70 | * Log (panic) messages from PlibC | ||
71 | */ | ||
72 | void | ||
73 | plibc_panic (int err, char *msg) | ||
74 | { | ||
75 | GNUNET_log (((err == | ||
76 | INT_MAX) ? GNUNET_ERROR_TYPE_DEBUG : GNUNET_ERROR_TYPE_ERROR), | ||
77 | "%s", msg); | ||
78 | } | ||
79 | |||
80 | /** | ||
81 | * @brief Initialize PlibC and set up Windows environment | ||
82 | * @param logging context, NULL means stderr | ||
83 | * @return Error code from winerror.h, ERROR_SUCCESS on success | ||
84 | */ | ||
85 | int | ||
86 | InitWinEnv () | ||
87 | { | ||
88 | int ret; | ||
89 | |||
90 | plibc_initialized (); | ||
91 | plibc_set_panic_proc (plibc_panic); | ||
92 | ret = plibc_init ("GNU", PACKAGE); | ||
93 | |||
94 | /* don't load other DLLs twice */ | ||
95 | if (hNTDLL) | ||
96 | return ret; | ||
97 | |||
98 | hNTDLL = LoadLibrary ("ntdll.dll"); | ||
99 | |||
100 | /* Function to get CPU usage under Win NT */ | ||
101 | if (hNTDLL) | ||
102 | { | ||
103 | GNNtQuerySystemInformation = (TNtQuerySystemInformation) | ||
104 | GetProcAddress (hNTDLL, "NtQuerySystemInformation"); | ||
105 | } | ||
106 | else | ||
107 | { | ||
108 | GNNtQuerySystemInformation = NULL; | ||
109 | } | ||
110 | |||
111 | /* Functions to get information about a network adapter */ | ||
112 | hIphlpapi = LoadLibrary ("iphlpapi.dll"); | ||
113 | if (hIphlpapi) | ||
114 | { | ||
115 | GNGetIfEntry = (TGetIfEntry) GetProcAddress (hIphlpapi, "GetIfEntry"); | ||
116 | GNGetIpAddrTable = (TGetIpAddrTable) GetProcAddress (hIphlpapi, | ||
117 | "GetIpAddrTable"); | ||
118 | GNGetIfTable = (TGetIfTable) GetProcAddress (hIphlpapi, "GetIfTable"); | ||
119 | GNGetBestInterface = (TGetBestInterface) GetProcAddress (hIphlpapi, | ||
120 | "GetBestInterface"); | ||
121 | GGetAdaptersInfo = (TGetAdaptersInfo) GetProcAddress (hIphlpapi, | ||
122 | "GetAdaptersInfo"); | ||
123 | } | ||
124 | else | ||
125 | { | ||
126 | GNGetIfEntry = NULL; | ||
127 | GNGetIpAddrTable = NULL; | ||
128 | GNGetIfTable = NULL; | ||
129 | GNGetBestInterface = NULL; | ||
130 | GGetAdaptersInfo = NULL; | ||
131 | } | ||
132 | |||
133 | /* Service & Account functions */ | ||
134 | hAdvapi = LoadLibrary ("advapi32.dll"); | ||
135 | if (hAdvapi) | ||
136 | { | ||
137 | GNOpenSCManager = (TOpenSCManager) | ||
138 | GetProcAddress (hAdvapi, "OpenSCManagerA"); | ||
139 | GNCreateService = (TCreateService) | ||
140 | GetProcAddress (hAdvapi, "CreateServiceA"); | ||
141 | GNCloseServiceHandle = (TCloseServiceHandle) | ||
142 | GetProcAddress (hAdvapi, "CloseServiceHandle"); | ||
143 | GNDeleteService = (TDeleteService) | ||
144 | GetProcAddress (hAdvapi, "DeleteService"); | ||
145 | GNRegisterServiceCtrlHandler = (TRegisterServiceCtrlHandler) | ||
146 | GetProcAddress (hAdvapi, "RegisterServiceCtrlHandlerA"); | ||
147 | GNSetServiceStatus = (TSetServiceStatus) | ||
148 | GetProcAddress (hAdvapi, "SetServiceStatus"); | ||
149 | GNStartServiceCtrlDispatcher = (TStartServiceCtrlDispatcher) | ||
150 | GetProcAddress (hAdvapi, "StartServiceCtrlDispatcherA"); | ||
151 | GNControlService = (TControlService) | ||
152 | GetProcAddress (hAdvapi, "ControlService"); | ||
153 | GNOpenService = (TOpenService) GetProcAddress (hAdvapi, "OpenServiceA"); | ||
154 | |||
155 | GNLsaOpenPolicy = (TLsaOpenPolicy) | ||
156 | GetProcAddress (hAdvapi, "LsaOpenPolicy"); | ||
157 | GNLsaAddAccountRights = (TLsaAddAccountRights) | ||
158 | GetProcAddress (hAdvapi, "LsaAddAccountRights"); | ||
159 | GNLsaRemoveAccountRights = (TLsaRemoveAccountRights) | ||
160 | GetProcAddress (hAdvapi, "LsaRemoveAccountRights"); | ||
161 | GNLsaClose = (TLsaClose) GetProcAddress (hAdvapi, "LsaClose"); | ||
162 | GNLookupAccountName = (TLookupAccountName) | ||
163 | GetProcAddress (hAdvapi, "LookupAccountNameA"); | ||
164 | |||
165 | GNGetFileSecurity = (TGetFileSecurity) | ||
166 | GetProcAddress (hAdvapi, "GetFileSecurityA"); | ||
167 | GNInitializeSecurityDescriptor = (TInitializeSecurityDescriptor) | ||
168 | GetProcAddress (hAdvapi, "InitializeSecurityDescriptor"); | ||
169 | GNGetSecurityDescriptorDacl = (TGetSecurityDescriptorDacl) | ||
170 | GetProcAddress (hAdvapi, "GetSecurityDescriptorDacl"); | ||
171 | GNGetAclInformation = (TGetAclInformation) | ||
172 | GetProcAddress (hAdvapi, "GetAclInformation"); | ||
173 | GNInitializeAcl = (TInitializeAcl) | ||
174 | GetProcAddress (hAdvapi, "InitializeAcl"); | ||
175 | GNGetAce = (TGetAce) GetProcAddress (hAdvapi, "GetAce"); | ||
176 | GNEqualSid = (TEqualSid) GetProcAddress (hAdvapi, "EqualSid"); | ||
177 | GNAddAce = (TAddAce) GetProcAddress (hAdvapi, "AddAce"); | ||
178 | GNAddAccessAllowedAce = (TAddAccessAllowedAce) | ||
179 | GetProcAddress (hAdvapi, "AddAccessAllowedAce"); | ||
180 | GNSetNamedSecurityInfo = (TSetNamedSecurityInfo) | ||
181 | GetProcAddress (hAdvapi, "SetNamedSecurityInfoA"); | ||
182 | } | ||
183 | else | ||
184 | { | ||
185 | GNOpenSCManager = NULL; | ||
186 | GNCreateService = NULL; | ||
187 | GNCloseServiceHandle = NULL; | ||
188 | GNDeleteService = NULL; | ||
189 | GNRegisterServiceCtrlHandler = NULL; | ||
190 | GNSetServiceStatus = NULL; | ||
191 | GNStartServiceCtrlDispatcher = NULL; | ||
192 | GNControlService = NULL; | ||
193 | GNOpenService = NULL; | ||
194 | |||
195 | GNLsaOpenPolicy = NULL; | ||
196 | GNLsaAddAccountRights = NULL; | ||
197 | GNLsaRemoveAccountRights = NULL; | ||
198 | GNLsaClose = NULL; | ||
199 | GNLookupAccountName = NULL; | ||
200 | |||
201 | GNGetFileSecurity = NULL; | ||
202 | GNInitializeSecurityDescriptor = NULL; | ||
203 | GNGetSecurityDescriptorDacl = NULL; | ||
204 | GNGetAclInformation = NULL; | ||
205 | GNInitializeAcl = NULL; | ||
206 | GNGetAce = NULL; | ||
207 | GNEqualSid = NULL; | ||
208 | GNAddAce = NULL; | ||
209 | GNAddAccessAllowedAce = NULL; | ||
210 | GNSetNamedSecurityInfo = NULL; | ||
211 | } | ||
212 | |||
213 | /* Account function */ | ||
214 | hNetapi = LoadLibrary ("netapi32.dll"); | ||
215 | if (hNetapi) | ||
216 | { | ||
217 | GNNetUserAdd = (TNetUserAdd) GetProcAddress (hNetapi, "NetUserAdd"); | ||
218 | GNNetUserSetInfo = (TNetUserSetInfo) | ||
219 | GetProcAddress (hNetapi, "NetUserSetInfo"); | ||
220 | } | ||
221 | else | ||
222 | { | ||
223 | GNNetUserAdd = NULL; | ||
224 | GNNetUserSetInfo = NULL; | ||
225 | } | ||
226 | |||
227 | return ret; | ||
228 | } | ||
229 | |||
230 | /** | ||
231 | * Clean up Windows environment | ||
232 | */ | ||
233 | void | ||
234 | ShutdownWinEnv () | ||
235 | { | ||
236 | plibc_shutdown (); | ||
237 | |||
238 | FreeLibrary (hNTDLL); | ||
239 | FreeLibrary (hIphlpapi); | ||
240 | FreeLibrary (hAdvapi); | ||
241 | FreeLibrary (hNetapi); | ||
242 | |||
243 | CoUninitialize (); | ||
244 | } | ||
245 | |||
246 | #endif /* MINGW */ | ||
247 | |||
248 | #if !HAVE_ATOLL | ||
249 | long long | ||
250 | atoll (const char *nptr) | ||
251 | { | ||
252 | return atol (nptr); | ||
253 | } | ||
254 | #endif | ||