mirror of
https://gitea.tendokyu.moe/Dniel97/segatools.git
synced 2024-11-11 23:17:08 +01:00
util/lib.c: Add module file path utility
This commit is contained in:
parent
bbb7cdf4a5
commit
8412ee2c16
29
util/lib.c
Normal file
29
util/lib.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
wchar_t *module_file_name(HMODULE module)
|
||||||
|
{
|
||||||
|
size_t buf_len;
|
||||||
|
DWORD len;
|
||||||
|
wchar_t *buf;
|
||||||
|
|
||||||
|
buf_len = MAX_PATH;
|
||||||
|
buf = malloc(buf_len * sizeof(*buf));
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
len = GetModuleFileNameW(module, buf, buf_len);
|
||||||
|
|
||||||
|
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
|
||||||
|
buf_len = len;
|
||||||
|
buf = realloc(buf, buf_len * sizeof(*buf));
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf_len *= 2;
|
||||||
|
buf = realloc(buf, buf_len * sizeof(*buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf;
|
||||||
|
}
|
5
util/lib.h
Normal file
5
util/lib.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
wchar_t *module_file_name(HMODULE module);
|
@ -17,6 +17,8 @@ util_lib = static_library(
|
|||||||
'dprintf.h',
|
'dprintf.h',
|
||||||
'dump.c',
|
'dump.c',
|
||||||
'dump.h',
|
'dump.h',
|
||||||
|
'lib.c',
|
||||||
|
'lib.h',
|
||||||
'str.c',
|
'str.c',
|
||||||
'str.h',
|
'str.h',
|
||||||
],
|
],
|
||||||
|
Loading…
Reference in New Issue
Block a user