]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/libudev/libudev.c
libudev: drop unused element in udev struct
[thirdparty/systemd.git] / src / libudev / libudev.c
CommitLineData
53e1b683 1/* SPDX-License-Identifier: LGPL-2.1+ */
33a5cc29 2
07630cea
LP
3#include <ctype.h>
4#include <stdarg.h>
5#include <stddef.h>
33a5cc29
KS
6#include <stdio.h>
7#include <stdlib.h>
33a5cc29 8#include <string.h>
33a5cc29 9
b4bbcaa9
TA
10#include "libudev.h"
11
b5efdb8a 12#include "alloc-util.h"
3ffd4af2 13#include "fd-util.h"
33a5cc29 14#include "libudev-private.h"
4db17f29 15#include "missing.h"
07630cea 16#include "string-util.h"
33a5cc29 17
ce1d6d7f
KS
18/**
19 * SECTION:libudev
20 * @short_description: libudev context
ce1d6d7f
KS
21 */
22
1e511322
KS
23/**
24 * udev:
25 *
ce1d6d7f 26 * Opaque object representing the library context.
1e511322 27 */
ba6929f6 28struct udev {
3c6ac219 29 unsigned n_ref;
912541b0 30 void *userdata;
ba6929f6
KS
31};
32
1e511322
KS
33/**
34 * udev_get_userdata:
35 * @udev: udev library context
36 *
37 * Retrieve stored data pointer from library context. This might be useful
25e773ee 38 * to access from callbacks.
1e511322
KS
39 *
40 * Returns: stored userdata
41 **/
25e773ee 42_public_ void *udev_get_userdata(struct udev *udev) {
912541b0
KS
43 if (udev == NULL)
44 return NULL;
45 return udev->userdata;
c8e32461
KS
46}
47
1e511322
KS
48/**
49 * udev_set_userdata:
50 * @udev: udev library context
51 * @userdata: data pointer
52 *
53 * Store custom @userdata in the library context.
54 **/
25e773ee 55_public_ void udev_set_userdata(struct udev *udev, void *userdata) {
912541b0
KS
56 if (udev == NULL)
57 return;
58 udev->userdata = userdata;
c8e32461
KS
59}
60
33a5cc29
KS
61/**
62 * udev_new:
63 *
e8112e67 64 * Create udev library context. This only allocates the basic data structure.
33a5cc29
KS
65 *
66 * The initial refcount is 1, and needs to be decremented to
be7de409 67 * release the resources of the udev library context.
33a5cc29
KS
68 *
69 * Returns: a new udev library context
70 **/
25e773ee 71_public_ struct udev *udev_new(void) {
912541b0 72 struct udev *udev;
912541b0 73
955d98c9 74 udev = new0(struct udev, 1);
9e70a49d 75 if (!udev) {
309f631d 76 errno = ENOMEM;
912541b0 77 return NULL;
9e70a49d 78 }
3c6ac219 79 udev->n_ref = 1;
912541b0 80
912541b0 81 return udev;
33a5cc29
KS
82}
83
84/**
85 * udev_ref:
86 * @udev: udev library context
87 *
88 * Take a reference of the udev library context.
89 *
90 * Returns: the passed udev library context
91 **/
3c6ac219 92DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev, udev);
33a5cc29
KS
93
94/**
95 * udev_unref:
96 * @udev: udev library context
97 *
98 * Drop a reference of the udev library context. If the refcount
be7de409 99 * reaches zero, the resources of the context will be released.
33a5cc29 100 *
c1959569 101 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
33a5cc29 102 **/
25e773ee 103_public_ struct udev *udev_unref(struct udev *udev) {
3c6ac219 104 if (!udev)
20bbd54f 105 return NULL;
3c6ac219
YW
106
107 assert(udev->n_ref > 0);
108 udev->n_ref--;
109 if (udev->n_ref > 0)
110 /* This is different from our convetion, but let's keep backward
111 * compatibility. So, do not use DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC()
112 * macro to define this function. */
20bbd54f 113 return udev;
3c6ac219 114
5fecf46d 115 return mfree(udev);
33a5cc29
KS
116}
117
118/**
119 * udev_set_log_fn:
120 * @udev: udev library context
f47ad593 121 * @log_fn: function to be called for log messages
33a5cc29 122 *
25e773ee 123 * This function is deprecated.
33a5cc29
KS
124 *
125 **/
54cf0b7f 126_public_ void udev_set_log_fn(struct udev *udev,
912541b0
KS
127 void (*log_fn)(struct udev *udev,
128 int priority, const char *file, int line, const char *fn,
25e773ee
KS
129 const char *format, va_list args)) {
130 return;
7d563a17
KS
131}
132
1e511322
KS
133/**
134 * udev_get_log_priority:
135 * @udev: udev library context
136 *
25e773ee 137 * This function is deprecated.
1e511322 138 *
1e511322 139 **/
25e773ee
KS
140_public_ int udev_get_log_priority(struct udev *udev) {
141 return log_get_max_level();
7d563a17
KS
142}
143
1e511322
KS
144/**
145 * udev_set_log_priority:
146 * @udev: udev library context
f47ad593 147 * @priority: the new log priority
1e511322 148 *
25e773ee
KS
149 * This function is deprecated.
150 *
1e511322 151 **/
25e773ee
KS
152_public_ void udev_set_log_priority(struct udev *udev, int priority) {
153 log_set_max_level(priority);
7d563a17 154}