Debian Codegraph @

src/cli/win32/sighandler.c

raw
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #include "git2_util.h"
9 #include <windows.h>
10
11 #include "sighandler.h"
12
13 static void (*interrupt_handler)(void) = NULL;
14
15 static BOOL WINAPI interrupt_proxy(DWORD signal)
16 {
17 GIT_UNUSED(signal);
18 interrupt_handler();
19 return TRUE;
20 }
21
22 int cli_sighandler_set_interrupt(void (*handler)(void))
23 {
24 BOOL result;
25
26 if ((interrupt_handler = handler) != NULL)
27 result = SetConsoleCtrlHandler(interrupt_proxy, FALSE);
28 else
29 result = SetConsoleCtrlHandler(NULL, FALSE);
30
31 if (!result) {
32 git_error_set(GIT_ERROR_OS, "could not set control control handler");
33 return -1;
34 }
35
36 return 0;
37 }