1 /* gwin32-private.c - private glib functions for gwin32.c
3 * Copyright 2019 Руслан Ижбулатов
5 * SPDX-License-Identifier: LGPL-2.1-or-later
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, see <http://www.gnu.org/licenses/>.
21 /* Copy @cmdline into @debugger, and substitute @pid for `%p`
22 * and @event for `%e`.
23 * If @debugger_size (in wchar_ts) is overflowed, return %FALSE.
24 * Also returns %FALSE when `%` is followed by anything other
28 _g_win32_subst_pid_and_event_w (wchar_t *local_debugger,
30 const wchar_t *cmdline,
34 gsize i = 0, dbg_i = 0;
35 /* These are integers, and they can't be longer than 20 characters
36 * even when they are 64-bit and in decimal notation.
37 * Use 30 just to be sure.
39 #define STR_BUFFER_SIZE 30
40 wchar_t pid_str[STR_BUFFER_SIZE] = {0};
42 wchar_t event_str[STR_BUFFER_SIZE] = {0};
45 _snwprintf_s (pid_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), L"%lu", pid);
46 pid_str[G_N_ELEMENTS (pid_str) - 1] = 0;
47 pid_str_len = wcslen (pid_str);
48 _snwprintf_s (event_str, STR_BUFFER_SIZE, G_N_ELEMENTS (pid_str), L"%Iu", event);
49 event_str[G_N_ELEMENTS (pid_str) - 1] = 0;
50 event_str_len = wcslen (event_str);
51 #undef STR_BUFFER_SIZE
53 while (cmdline[i] != 0 && dbg_i < debugger_size)
55 if (cmdline[i] != L'%')
56 local_debugger[dbg_i++] = cmdline[i++];
57 else if (cmdline[i + 1] == L'p')
60 while (j < pid_str_len && dbg_i < debugger_size)
61 local_debugger[dbg_i++] = pid_str[j++];
64 else if (cmdline[i + 1] == L'e')
67 while (j < event_str_len && dbg_i < debugger_size)
68 local_debugger[dbg_i++] = event_str[j++];
74 if (dbg_i < debugger_size)
75 local_debugger[dbg_i] = 0;