comparison common/util.c @ 905:698b6a9bd75e

Fix coding style for C code astyle --style=gnu --indent=spaces=2
author Andre Heinecke <andre.heinecke@intevation.de>
date Wed, 13 Aug 2014 15:49:47 +0200
parents f89b41fa7048
children 427e2e18b8c8
comparison
equal deleted inserted replaced
904:f89b41fa7048 905:698b6a9bd75e
34 ex_size = 0, 34 ex_size = 0,
35 dwRet = 0; 35 dwRet = 0;
36 LONG ret = 0; 36 LONG ret = 0;
37 char *retval = NULL; 37 char *retval = NULL;
38 wchar_t *buf = NULL, 38 wchar_t *buf = NULL,
39 *ex_buf = NULL; 39 *ex_buf = NULL;
40 if (root == NULL || key == NULL || name == NULL) 40 if (root == NULL || key == NULL || name == NULL)
41 { 41 {
42 ERRORPRINTF ("Invalid call to read_registry_string"); 42 ERRORPRINTF ("Invalid call to read_registry_string");
43 return NULL; 43 return NULL;
44 } 44 }
137 * @returns true if the paths are the same. 137 * @returns true if the paths are the same.
138 */ 138 */
139 bool 139 bool
140 paths_equal (const char *path1, const char *path2) 140 paths_equal (const char *path1, const char *path2)
141 { 141 {
142 bool ret = false; 142 bool ret = false;
143 wchar_t buf1[MAX_PATH], 143 wchar_t buf1[MAX_PATH],
144 buf2[MAX_PATH]; 144 buf2[MAX_PATH];
145 wchar_t *wpath1 = NULL, 145 wchar_t *wpath1 = NULL,
146 *wpath2 = NULL; 146 *wpath2 = NULL;
147 DWORD retval = 0; 147 DWORD retval = 0;
148 148
149 if (!path1 || !path2) 149 if (!path1 || !path2)
150 { 150 {
151 return false; 151 return false;
152 } 152 }
153 153
154 wpath1 = utf8_to_wchar(path1, strnlen(path1, MAX_PATH)); 154 wpath1 = utf8_to_wchar(path1, strnlen(path1, MAX_PATH));
155 wpath2 = utf8_to_wchar(path2, strnlen(path2, MAX_PATH)); 155 wpath2 = utf8_to_wchar(path2, strnlen(path2, MAX_PATH));
156 156
157 if (wpath1 == NULL || wpath2 == NULL) 157 if (wpath1 == NULL || wpath2 == NULL)
158 { 158 {
159 ERRORPRINTF ("Failed to convert paths to wchar."); 159 ERRORPRINTF ("Failed to convert paths to wchar.");
160 goto done; 160 goto done;
161 } 161 }
162 162
163 retval = GetFullPathNameW (wpath1, MAX_PATH, buf1, NULL); 163 retval = GetFullPathNameW (wpath1, MAX_PATH, buf1, NULL);
164 if (retval >= MAX_PATH || retval != wcsnlen (buf1, MAX_PATH)) 164 if (retval >= MAX_PATH || retval != wcsnlen (buf1, MAX_PATH))
165 { 165 {
166 ERRORPRINTF ("Path1 too long."); 166 ERRORPRINTF ("Path1 too long.");
167 goto done; 167 goto done;
168 } 168 }
169 if (retval == 0) 169 if (retval == 0)
170 { 170 {
171 PRINTLASTERROR ("Failed to get Full Path name."); 171 PRINTLASTERROR ("Failed to get Full Path name.");
172 goto done; 172 goto done;
173 } 173 }
174 174
175 retval = GetFullPathNameW (wpath2, MAX_PATH, buf2, NULL); 175 retval = GetFullPathNameW (wpath2, MAX_PATH, buf2, NULL);
176 if (retval >= MAX_PATH || retval != wcsnlen (buf2, MAX_PATH)) 176 if (retval >= MAX_PATH || retval != wcsnlen (buf2, MAX_PATH))
177 { 177 {
178 ERRORPRINTF ("Path2 too long."); 178 ERRORPRINTF ("Path2 too long.");
179 goto done; 179 goto done;
180 } 180 }
181 if (retval == 0) 181 if (retval == 0)
182 { 182 {
183 PRINTLASTERROR ("Failed to get Full Path name."); 183 PRINTLASTERROR ("Failed to get Full Path name.");
184 goto done; 184 goto done;
185 } 185 }
186 186
187 ret = wcscmp (buf1, buf2) == 0; 187 ret = wcscmp (buf1, buf2) == 0;
188 done: 188 done:
189 xfree (wpath1); 189 xfree (wpath1);
190 xfree (wpath2); 190 xfree (wpath2);
191 191
192 return ret; 192 return ret;
193 } 193 }
194 194
195 char * 195 char *
196 get_install_dir() 196 get_install_dir()
197 { 197 {
242 } 242 }
243 243
244 PSID 244 PSID
245 get_process_owner(HANDLE hProcess) 245 get_process_owner(HANDLE hProcess)
246 { 246 {
247 HANDLE hToken = NULL; 247 HANDLE hToken = NULL;
248 PSID sid; 248 PSID sid;
249 249
250 if (hProcess == NULL) 250 if (hProcess == NULL)
251 { 251 {
252 ERRORPRINTF ("invalid call to get_process_owner"); 252 ERRORPRINTF ("invalid call to get_process_owner");
253 return NULL; 253 return NULL;
254 } 254 }
255 255
256 OpenProcessToken(hProcess, TOKEN_READ, &hToken); 256 OpenProcessToken(hProcess, TOKEN_READ, &hToken);
257 if (hToken) 257 if (hToken)
258 { 258 {
259 DWORD size = 0; 259 DWORD size = 0;
260 PTOKEN_USER userStruct; 260 PTOKEN_USER userStruct;
261 261
262 // check how much space is needed 262 // check how much space is needed
263 GetTokenInformation(hToken, TokenUser, NULL, 0, &size); 263 GetTokenInformation(hToken, TokenUser, NULL, 0, &size);
264 if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) 264 if (ERROR_INSUFFICIENT_BUFFER == GetLastError())
265 { 265 {
266 userStruct = (PTOKEN_USER) xmalloc (size); 266 userStruct = (PTOKEN_USER) xmalloc (size);
267 GetTokenInformation(hToken, TokenUser, userStruct, size, &size); 267 GetTokenInformation(hToken, TokenUser, userStruct, size, &size);
268 268
269 sid = copy_sid(userStruct->User.Sid); 269 sid = copy_sid(userStruct->User.Sid);
270 CloseHandle(hToken); 270 CloseHandle(hToken);
271 xfree (userStruct); 271 xfree (userStruct);
272 return sid; 272 return sid;
273 } 273 }
274 } 274 }
275 return NULL; 275 return NULL;
276 } 276 }
277 277
278 bool 278 bool
279 is_system_install() 279 is_system_install()
280 { 280 {
281 char *reg_inst_dir = NULL, 281 char *reg_inst_dir = NULL,
282 *real_prefix = NULL; 282 *real_prefix = NULL;
283 bool ret = false; 283 bool ret = false;
284 284
285 reg_inst_dir = read_registry_string (HKEY_LOCAL_MACHINE, 285 reg_inst_dir = read_registry_string (HKEY_LOCAL_MACHINE,
286 L"Software\\"APPNAME, L""); 286 L"Software\\"APPNAME, L"");
287 287
311 311
312 char * 312 char *
313 get_install_dir() 313 get_install_dir()
314 { 314 {
315 char *retval = NULL, 315 char *retval = NULL,
316 *p = NULL, 316 *p = NULL,
317 buf[MAX_PATH_LINUX]; 317 buf[MAX_PATH_LINUX];
318 ssize_t ret; 318 ssize_t ret;
319 size_t path_len = 0; 319 size_t path_len = 0;
320 320
321 ret = readlink ("/proc/self/exe", buf, MAX_PATH_LINUX); 321 ret = readlink ("/proc/self/exe", buf, MAX_PATH_LINUX);
322 if (ret <= 0) 322 if (ret <= 0)

http://wald.intevation.org/projects/trustbridge/