/src/fwupd/libfwupdplugin/fu-kenv.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2021 Richard Hughes <richard@hughsie.com> |
3 | | * |
4 | | * SPDX-License-Identifier: LGPL-2.1-or-later |
5 | | */ |
6 | | |
7 | | #include "config.h" |
8 | | |
9 | | #ifdef HAVE_KENV_H |
10 | | #include <kenv.h> |
11 | | #endif |
12 | | |
13 | | #include "fwupd-error.h" |
14 | | |
15 | | #include "fu-kenv.h" |
16 | | |
17 | | /** |
18 | | * fu_kenv_get_string: |
19 | | * @key: a kenv key, e.g. `smbios.bios.version` |
20 | | * @error: (nullable): optional return location for an error |
21 | | * |
22 | | * Gets a BSD kernel environment string. This will not work on Linux or |
23 | | * Windows. |
24 | | * |
25 | | * Returns: (transfer full): a string, or %NULL if the @key was not found |
26 | | * |
27 | | * Since: 1.6.1 |
28 | | **/ |
29 | | gchar * |
30 | | fu_kenv_get_string(const gchar *key, GError **error) |
31 | 0 | { |
32 | | #ifdef HAVE_KENV_H |
33 | | gchar buf[128] = {'\0'}; |
34 | | |
35 | | g_return_val_if_fail(key != NULL, NULL); |
36 | | g_return_val_if_fail(error == NULL || *error == NULL, NULL); |
37 | | |
38 | | if (kenv(KENV_GET, key, buf, sizeof(buf)) == -1) { |
39 | | g_set_error(error, |
40 | | FWUPD_ERROR, |
41 | | FWUPD_ERROR_READ, |
42 | | "cannot get kenv request for %s", |
43 | | key); |
44 | | return NULL; |
45 | | } |
46 | | return g_strndup(buf, sizeof(buf)); |
47 | | #else |
48 | 0 | g_set_error_literal(error, FWUPD_ERROR, FWUPD_ERROR_NOT_SUPPORTED, "kenv not supported"); |
49 | 0 | return NULL; |
50 | 0 | #endif |
51 | 0 | } |