Line data Source code
1 : #include <glib.h>
2 : #include <glib-object.h>
3 :
4 : #include "extra_arg.h"
5 :
6 : /**
7 : * bd_extra_arg_copy:
8 : * @arg: (nullable): %BDExtraArg to copy
9 : *
10 : * Creates a new copy of @arg.
11 : */
12 4 : BDExtraArg* bd_extra_arg_copy (BDExtraArg *arg) {
13 4 : if (arg == NULL)
14 0 : return NULL;
15 :
16 4 : BDExtraArg *ret = g_new0 (BDExtraArg, 1);
17 4 : ret->opt = g_strdup (arg->opt);
18 4 : ret->val = g_strdup (arg->val);
19 :
20 4 : return ret;
21 : }
22 :
23 : /**
24 : * bd_extra_arg_free:
25 : * @arg: (nullable): %BDExtraArg to free
26 : *
27 : * Frees @arg.
28 : */
29 154 : void bd_extra_arg_free (BDExtraArg *arg) {
30 154 : if (arg == NULL)
31 0 : return;
32 :
33 154 : g_free (arg->opt);
34 154 : g_free (arg->val);
35 154 : g_free (arg);
36 : }
37 :
38 : /**
39 : * bd_extra_arg_list_free:
40 : * @args: (nullable) (array zero-terminated=1): A list of %BDExtraArg to free
41 : *
42 : * Frees @args and all its elements.
43 : */
44 52 : void bd_extra_arg_list_free (BDExtraArg **args) {
45 : BDExtraArg **a;
46 :
47 52 : if (args == NULL)
48 0 : return;
49 :
50 97 : for (a = args; *a; a++)
51 45 : bd_extra_arg_free (*a);
52 52 : g_free (args);
53 : }
54 :
55 112 : GType bd_extra_arg_get_type (void) {
56 : static GType type = 0;
57 :
58 112 : if (G_UNLIKELY (!type))
59 1 : type = g_boxed_type_register_static ("BDExtraArg",
60 : (GBoxedCopyFunc) bd_extra_arg_copy,
61 : (GBoxedFreeFunc) bd_extra_arg_free);
62 :
63 112 : return type;
64 : }
65 :
66 : /**
67 : * bd_extra_arg_new: (constructor)
68 : * @opt: extra option
69 : * @val: value for the extra option @opt
70 : *
71 : * Example of calling bd_fs_xfs_mkfs() with an extra argument.
72 : * This will result in calling `mkfs.xfs` with `-L label`.
73 : *
74 : * |[<!-- language="C" -->
75 : * BDExtraArg label_arg = {"-L", "label"};
76 : * const BDExtraArg *extra_args[2] = {&label_arg, NULL};
77 : *
78 : * ret = bd_fs_xfs_mkfs ("/dev/sda", extra_args, error);
79 : *
80 : * ]|
81 : *
82 : * Returns: (transfer full): a new extra argument
83 : */
84 150 : BDExtraArg* bd_extra_arg_new (const gchar *opt, const gchar *val) {
85 150 : BDExtraArg *ret = g_new0 (BDExtraArg, 1);
86 150 : ret->opt = g_strdup (opt ? opt : "");
87 150 : ret->val = g_strdup (val ? val : "");
88 :
89 150 : return ret;
90 : }
|