Branch data Line data Source code
1 : : /* -*- mode: C++; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
2 : : // SPDX-License-Identifier: MIT OR LGPL-2.0-or-later
3 : : // SPDX-FileCopyrightText: 2008 litl, LLC
4 : :
5 : : #include <config.h>
6 : :
7 : : #include <glib.h>
8 : :
9 : : #include "util/misc.h"
10 : :
11 : 512 : bool gjs_environment_variable_is_set(const char* env_variable_name) {
12 : : const char *s;
13 : :
14 : 512 : s = g_getenv(env_variable_name);
15 [ + - ]: 512 : if (!s)
16 : 512 : return false;
17 : :
18 [ # # ]: 0 : if (*s == '\0')
19 : 0 : return false;
20 : :
21 : 0 : return true;
22 : : }
23 : :
24 : : /**
25 : : * gjs_g_strv_concat:
26 : : *
27 : : * Concate an array of string arrays to one string array. The strings in each
28 : : * array is copied to the resulting array.
29 : : *
30 : : * @strv_array: array of 0-terminated arrays of strings. Null elements are
31 : : * allowed.
32 : : * @len: number of arrays in @strv_array
33 : : *
34 : : * Returns: (transfer full): a newly allocated 0-terminated array of strings.
35 : : */
36 : 2 : char** gjs_g_strv_concat(char*** strv_array, int len) {
37 : 2 : GPtrArray* array = g_ptr_array_sized_new(16);
38 : :
39 [ + + ]: 6 : for (int i = 0; i < len; i++) {
40 : 4 : char** strv = strv_array[i];
41 [ + + ]: 4 : if (!strv)
42 : 1 : continue;
43 : :
44 [ + + ]: 5 : for (int j = 0; strv[j]; ++j)
45 : 4 : g_ptr_array_add(array, g_strdup(strv[j]));
46 : : }
47 : :
48 : 2 : g_ptr_array_add(array, nullptr);
49 : :
50 : 2 : return reinterpret_cast<char**>(g_ptr_array_free(array, false));
51 : : }
|