hook/iohook.c: Add iohook_open_nul_fd()

This provides a replacement for iohook_open_dummy_fd() whose error
handling is more consistent with the rest of this library.
This commit is contained in:
Decaf Code
2019-11-03 10:57:33 -05:00
parent f084531454
commit 69f7e3b48c
2 changed files with 35 additions and 1 deletions
+28
View File
@@ -277,6 +277,7 @@ static void iohook_init(void)
iohook_initted = true;
}
// Deprecated
HANDLE iohook_open_dummy_fd(void)
{
iohook_init();
@@ -291,6 +292,33 @@ HANDLE iohook_open_dummy_fd(void)
NULL);
}
HRESULT iohook_open_nul_fd(HANDLE *out)
{
HANDLE fd;
assert(out != NULL);
*out = NULL;
iohook_init();
fd = next_CreateFileW(
L"NUL",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL);
if (fd == NULL) {
return HRESULT_FROM_WIN32(GetLastError());
}
*out = fd;
return S_OK;
}
HRESULT iohook_push_handler(iohook_fn_t fn)
{
iohook_fn_t *new_array;
+7 -1
View File
@@ -39,6 +39,12 @@ struct irp {
typedef HRESULT (*iohook_fn_t)(struct irp *irp);
HANDLE iohook_open_dummy_fd(void);
HANDLE iohook_open_dummy_fd(void)
#ifdef __GNUC__
__attribute__((deprecated("Use iohook_open_nul_fd instead")))
#endif
;
HRESULT iohook_open_nul_fd(HANDLE *fd);
HRESULT iohook_push_handler(iohook_fn_t fn);
HRESULT iohook_invoke_next(struct irp *irp);