diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2020-05-12 08:56:55 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2022-04-14 09:59:07 -0400 |
| commit | 7babe76f97822c701050c6ee8d3984462f73c27f (patch) | |
| tree | 1b4555cd7e810c9f79b2de325a70f25e233b7b1f /src/cli/win32 | |
| parent | 48506f2ba4b5ec9cd3d9b3952ae9c7e870bbe33a (diff) | |
| download | libgit2-7babe76f97822c701050c6ee8d3984462f73c27f.tar.gz | |
cli: introduce signal handler
Provide a mechanism to add a signal handler for Unix or Win32.
Diffstat (limited to 'src/cli/win32')
| -rw-r--r-- | src/cli/win32/sighandler.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/cli/win32/sighandler.c b/src/cli/win32/sighandler.c new file mode 100644 index 000000000..cc0b64640 --- /dev/null +++ b/src/cli/win32/sighandler.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) the libgit2 contributors. All rights reserved. + * + * This file is part of libgit2, distributed under the GNU GPL v2 with + * a Linking Exception. For full terms see the included COPYING file. + */ + +#include "git2_util.h" +#include <windows.h> + +#include "cli.h" + +static void (*interrupt_handler)(void) = NULL; + +static BOOL WINAPI interrupt_proxy(DWORD signal) +{ + GIT_UNUSED(signal); + interrupt_handler(); + return TRUE; +} + +int cli_sighandler_set_interrupt(void (*handler)(void)) +{ + BOOL result; + + if ((interrupt_handler = handler) != NULL) + result = SetConsoleCtrlHandler(interrupt_proxy, FALSE); + else + result = SetConsoleCtrlHandler(NULL, FALSE); + + if (!result) { + git_error_set(GIT_ERROR_OS, "could not set control control handler"); + return -1; + } + + return 0; +} |
