diff options
author | Ron Yorston <rmy@pobox.com> | 2021-08-14 10:34:10 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2021-08-14 13:12:29 +0100 |
commit | f1453b79a582d50e66fe68744abac64f384f91b1 (patch) | |
tree | c642297070a5db75ad9fd43a5a3f7a8203eeb9c3 | |
parent | 04fd6cdcc6fc1f07938f7e2fa1a0d313a15617be (diff) | |
download | busybox-w32-f1453b79a582d50e66fe68744abac64f384f91b1.tar.gz busybox-w32-f1453b79a582d50e66fe68744abac64f384f91b1.tar.bz2 busybox-w32-f1453b79a582d50e66fe68744abac64f384f91b1.zip |
win32: code shrink
There doesn't seem to be any need to call OpenThreadToken() in
file_owner(): OpenProcessToken() should suffice.
Also, tidy up gethomedir() without any change in functionality.
Saves 56 bytes.
-rw-r--r-- | win32/mingw.c | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/win32/mingw.c b/win32/mingw.c index 74f738927..387220bef 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
@@ -486,8 +486,7 @@ static uid_t file_owner(HANDLE fh) | |||
486 | DWORD ret = 0; | 486 | DWORD ret = 0; |
487 | 487 | ||
488 | initialised = 1; | 488 | initialised = 1; |
489 | if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, TRUE, &token) || | 489 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { |
490 | OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token)) { | ||
491 | GetTokenInformation(token, TokenUser, NULL, 0, &ret); | 490 | GetTokenInformation(token, TokenUser, NULL, 0, &ret); |
492 | if (ret <= 0 || (user=malloc(ret)) == NULL || | 491 | if (ret <= 0 || (user=malloc(ret)) == NULL || |
493 | !GetTokenInformation(token, TokenUser, user, ret, &ret)) { | 492 | !GetTokenInformation(token, TokenUser, user, ret, &ret)) { |
@@ -988,21 +987,22 @@ int mingw_rename(const char *pold, const char *pnew) | |||
988 | static char *gethomedir(void) | 987 | static char *gethomedir(void) |
989 | { | 988 | { |
990 | static char *buf = NULL; | 989 | static char *buf = NULL; |
991 | DWORD len = PATH_MAX; | ||
992 | HANDLE h; | ||
993 | DECLARE_PROC_ADDR(BOOL, GetUserProfileDirectoryA, HANDLE, LPSTR, LPDWORD); | 990 | DECLARE_PROC_ADDR(BOOL, GetUserProfileDirectoryA, HANDLE, LPSTR, LPDWORD); |
994 | 991 | ||
995 | if (buf) | 992 | if (!buf) { |
996 | return buf; | 993 | DWORD len = PATH_MAX; |
997 | 994 | HANDLE h; | |
998 | buf = xzalloc(PATH_MAX); | ||
999 | if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h) ) | ||
1000 | return buf; | ||
1001 | 995 | ||
1002 | if (INIT_PROC_ADDR(userenv.dll, GetUserProfileDirectoryA)) | 996 | buf = xzalloc(len); |
1003 | GetUserProfileDirectoryA(h, buf, &len); | 997 | if (OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &h)) { |
1004 | CloseHandle(h); | 998 | if (INIT_PROC_ADDR(userenv.dll, GetUserProfileDirectoryA)) { |
1005 | return bs_to_slash(buf); | 999 | GetUserProfileDirectoryA(h, buf, &len); |
1000 | bs_to_slash(buf); | ||
1001 | } | ||
1002 | CloseHandle(h); | ||
1003 | } | ||
1004 | } | ||
1005 | return buf; | ||
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | #define NAME_LEN 100 | 1008 | #define NAME_LEN 100 |