sd_sys/id128.rs
1// sd-sys: FFI bindings to systemd for sd-id128 & sd-journal
2// Copyright (C) 2020 Christian Klaue [mail@ck76.de]
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU Affero General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU Affero General Public License for more details.
13//
14// You should have received a copy of the GNU Affero General Public License
15// along with this program. If not, see <https://www.gnu.org/licenses/>.
16use libc::{c_char, c_int};
17/// FFI data type mapping for sd-id128 as defined in libsystemd.
18///
19/// This data type should rarely be used directly. Crate sd-id128 defines a
20/// wrapper `ID128`.
21///
22/// While libsystemd defines the data type as a union of \[u8;16\] and \[u64;2\]
23/// currently sd-sys only supports the first.
24///
25/// <https://www.freedesktop.org/software/systemd/man/sd-id128.html>
26#[allow(non_camel_case_types)]
27#[repr(C)]
28#[derive(Debug, Default, Clone, PartialEq, Eq)]
29pub struct sd_id128 {
30 pub value: [u8; 16]
31}
32
33extern "C" {
34 /// `char *sd_id128_to_string(sd_id128_t id, char s[33]);`
35 ///
36 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_to_string.html#>
37 pub fn sd_id128_to_string(id: sd_id128, string: *const c_char) -> *mut c_char;
38 /// `int sd_id128_from_string(const char *s, sd_id128_t *ret);`
39 ///
40 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_to_string.html#>
41 pub fn sd_id128_from_string(string: *const c_char, id: *mut sd_id128) -> c_int;
42 /// `int sd_id128_randomize(sd_id128_t *ret);`
43 ///
44 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_randomize.html#>
45 pub fn sd_id128_randomize(id: *mut sd_id128) -> c_int;
46 /// `int sd_id128_get_machine(sd_id128_t *ret);`
47 ///
48 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html#>
49 pub fn sd_id128_get_machine(id: *mut sd_id128) -> c_int;
50 /// `int sd_id128_get_machine_app_specific(sd_id128_t app_id,
51 /// sd_id128_t *ret);`
52 ///
53 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html#>
54 pub fn sd_id128_get_machine_app_specific(app: sd_id128, machine: *mut sd_id128) -> c_int;
55 /// `int sd_id128_get_boot(sd_id128_t *ret);`
56 ///
57 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html#>
58 pub fn sd_id128_get_boot(id: *mut sd_id128) -> c_int;
59 /// `int sd_id128_get_boot_app_specific(sd_id128_t app_id,
60 /// sd_id128_t *ret);`
61 ///
62 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html#>
63 pub fn sd_id128_get_boot_app_specific(app: sd_id128, boot: *mut sd_id128) -> c_int;
64 /// `int sd_id128_get_invocation(sd_id128_t *ret);`
65 ///
66 /// <https://www.freedesktop.org/software/systemd/man/sd_id128_get_machine.html#>
67 pub fn sd_id128_get_invocation(id: *mut sd_id128) -> c_int;
68}