Mercurial > trustbridge
diff 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 |
line wrap: on
line diff
--- a/common/util.c Wed Aug 13 15:44:35 2014 +0200 +++ b/common/util.c Wed Aug 13 15:49:47 2014 +0200 @@ -36,7 +36,7 @@ LONG ret = 0; char *retval = NULL; wchar_t *buf = NULL, - *ex_buf = NULL; + *ex_buf = NULL; if (root == NULL || key == NULL || name == NULL) { ERRORPRINTF ("Invalid call to read_registry_string"); @@ -139,57 +139,57 @@ bool paths_equal (const char *path1, const char *path2) { - bool ret = false; - wchar_t buf1[MAX_PATH], - buf2[MAX_PATH]; - wchar_t *wpath1 = NULL, - *wpath2 = NULL; - DWORD retval = 0; - - if (!path1 || !path2) - { - return false; - } - - wpath1 = utf8_to_wchar(path1, strnlen(path1, MAX_PATH)); - wpath2 = utf8_to_wchar(path2, strnlen(path2, MAX_PATH)); - - if (wpath1 == NULL || wpath2 == NULL) - { - ERRORPRINTF ("Failed to convert paths to wchar."); - goto done; - } + bool ret = false; + wchar_t buf1[MAX_PATH], + buf2[MAX_PATH]; + wchar_t *wpath1 = NULL, + *wpath2 = NULL; + DWORD retval = 0; - retval = GetFullPathNameW (wpath1, MAX_PATH, buf1, NULL); - if (retval >= MAX_PATH || retval != wcsnlen (buf1, MAX_PATH)) - { - ERRORPRINTF ("Path1 too long."); - goto done; - } - if (retval == 0) - { - PRINTLASTERROR ("Failed to get Full Path name."); - goto done; - } + if (!path1 || !path2) + { + return false; + } - retval = GetFullPathNameW (wpath2, MAX_PATH, buf2, NULL); - if (retval >= MAX_PATH || retval != wcsnlen (buf2, MAX_PATH)) - { - ERRORPRINTF ("Path2 too long."); - goto done; - } - if (retval == 0) - { - PRINTLASTERROR ("Failed to get Full Path name."); - goto done; - } + wpath1 = utf8_to_wchar(path1, strnlen(path1, MAX_PATH)); + wpath2 = utf8_to_wchar(path2, strnlen(path2, MAX_PATH)); - ret = wcscmp (buf1, buf2) == 0; + if (wpath1 == NULL || wpath2 == NULL) + { + ERRORPRINTF ("Failed to convert paths to wchar."); + goto done; + } + + retval = GetFullPathNameW (wpath1, MAX_PATH, buf1, NULL); + if (retval >= MAX_PATH || retval != wcsnlen (buf1, MAX_PATH)) + { + ERRORPRINTF ("Path1 too long."); + goto done; + } + if (retval == 0) + { + PRINTLASTERROR ("Failed to get Full Path name."); + goto done; + } + + retval = GetFullPathNameW (wpath2, MAX_PATH, buf2, NULL); + if (retval >= MAX_PATH || retval != wcsnlen (buf2, MAX_PATH)) + { + ERRORPRINTF ("Path2 too long."); + goto done; + } + if (retval == 0) + { + PRINTLASTERROR ("Failed to get Full Path name."); + goto done; + } + + ret = wcscmp (buf1, buf2) == 0; done: - xfree (wpath1); - xfree (wpath2); + xfree (wpath1); + xfree (wpath2); - return ret; + return ret; } char * @@ -244,42 +244,42 @@ PSID get_process_owner(HANDLE hProcess) { - HANDLE hToken = NULL; - PSID sid; - - if (hProcess == NULL) - { - ERRORPRINTF ("invalid call to get_process_owner"); - return NULL; - } + HANDLE hToken = NULL; + PSID sid; - OpenProcessToken(hProcess, TOKEN_READ, &hToken); - if (hToken) - { - DWORD size = 0; - PTOKEN_USER userStruct; + if (hProcess == NULL) + { + ERRORPRINTF ("invalid call to get_process_owner"); + return NULL; + } - // check how much space is needed - GetTokenInformation(hToken, TokenUser, NULL, 0, &size); - if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) - { - userStruct = (PTOKEN_USER) xmalloc (size); - GetTokenInformation(hToken, TokenUser, userStruct, size, &size); + OpenProcessToken(hProcess, TOKEN_READ, &hToken); + if (hToken) + { + DWORD size = 0; + PTOKEN_USER userStruct; - sid = copy_sid(userStruct->User.Sid); - CloseHandle(hToken); - xfree (userStruct); - return sid; - } - } - return NULL; + // check how much space is needed + GetTokenInformation(hToken, TokenUser, NULL, 0, &size); + if (ERROR_INSUFFICIENT_BUFFER == GetLastError()) + { + userStruct = (PTOKEN_USER) xmalloc (size); + GetTokenInformation(hToken, TokenUser, userStruct, size, &size); + + sid = copy_sid(userStruct->User.Sid); + CloseHandle(hToken); + xfree (userStruct); + return sid; + } + } + return NULL; } bool is_system_install() { char *reg_inst_dir = NULL, - *real_prefix = NULL; + *real_prefix = NULL; bool ret = false; reg_inst_dir = read_registry_string (HKEY_LOCAL_MACHINE, @@ -313,8 +313,8 @@ get_install_dir() { char *retval = NULL, - *p = NULL, - buf[MAX_PATH_LINUX]; + *p = NULL, + buf[MAX_PATH_LINUX]; ssize_t ret; size_t path_len = 0;