mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 09:27:59 +00:00
Factor out Windows utility function get_system_dir().
The code to find out the location of the c:\windows\system32 directory was already present, in load_system32_dll(). Now it's moved out into a function of its own, so it can be called in other contexts.
This commit is contained in:
parent
d77ecacc27
commit
3de2f13b89
@ -10,6 +10,7 @@ add_sources_from_current_dir(utils
|
||||
utils/filename.c
|
||||
utils/fontspec.c
|
||||
utils/getdlgitemtext_alloc.c
|
||||
utils/get_system_dir.c
|
||||
utils/get_username.c
|
||||
utils/is_console_handle.c
|
||||
utils/load_system32_dll.c
|
||||
|
@ -566,6 +566,7 @@ HWND event_log_window(void);
|
||||
extern DWORD osMajorVersion, osMinorVersion, osPlatformId;
|
||||
void init_winver(void);
|
||||
void dll_hijacking_protection(void);
|
||||
const char *get_system_dir(void);
|
||||
HMODULE load_system32_dll(const char *libname);
|
||||
const char *win_strerror(int error);
|
||||
void restrict_process_acl(void);
|
||||
|
21
windows/utils/get_system_dir.c
Normal file
21
windows/utils/get_system_dir.c
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Wrapper function around GetSystemDirectory that deals with
|
||||
* allocating the output buffer, and also caches the result for future
|
||||
* calls.
|
||||
*/
|
||||
|
||||
#include "putty.h"
|
||||
|
||||
const char *get_system_dir(void)
|
||||
{
|
||||
static char *sysdir = NULL;
|
||||
static size_t sysdirsize = 0;
|
||||
|
||||
if (!sysdir) {
|
||||
size_t len;
|
||||
while ((len = GetSystemDirectory(sysdir, sysdirsize)) >= sysdirsize)
|
||||
sgrowarray(sysdir, sysdirsize, len);
|
||||
}
|
||||
|
||||
return sysdir;
|
||||
}
|
@ -8,18 +8,10 @@
|
||||
|
||||
HMODULE load_system32_dll(const char *libname)
|
||||
{
|
||||
static char *sysdir = NULL;
|
||||
static size_t sysdirsize = 0;
|
||||
char *fullpath;
|
||||
HMODULE ret;
|
||||
|
||||
if (!sysdir) {
|
||||
size_t len;
|
||||
while ((len = GetSystemDirectory(sysdir, sysdirsize)) >= sysdirsize)
|
||||
sgrowarray(sysdir, sysdirsize, len);
|
||||
}
|
||||
|
||||
fullpath = dupcat(sysdir, "\\", libname);
|
||||
fullpath = dupcat(get_system_dir(), "\\", libname);
|
||||
ret = LoadLibrary(fullpath);
|
||||
sfree(fullpath);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user