]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libudev/libudev.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
12 #include "alloc-util.h"
14 #include "libudev-private.h"
16 #include "string-util.h"
20 * @short_description: libudev context
26 * Opaque object representing the library context.
35 * @udev: udev library context
37 * Retrieve stored data pointer from library context. This might be useful
38 * to access from callbacks.
40 * Returns: stored userdata
42 _public_
void *udev_get_userdata(struct udev
*udev
) {
43 assert_return(udev
, NULL
);
45 return udev
->userdata
;
50 * @udev: udev library context
51 * @userdata: data pointer
53 * Store custom @userdata in the library context.
55 _public_
void udev_set_userdata(struct udev
*udev
, void *userdata
) {
59 udev
->userdata
= userdata
;
65 * Create udev library context. This only allocates the basic data structure.
67 * The initial refcount is 1, and needs to be decremented to
68 * release the resources of the udev library context.
70 * Returns: a new udev library context
72 _public_
struct udev
*udev_new(void) {
75 udev
= new(struct udev
, 1);
81 *udev
= (struct udev
) {
90 * @udev: udev library context
92 * Take a reference of the udev library context.
94 * Returns: the passed udev library context
96 DEFINE_PUBLIC_TRIVIAL_REF_FUNC(struct udev
, udev
);
100 * @udev: udev library context
102 * Drop a reference of the udev library context. If the refcount
103 * reaches zero, the resources of the context will be released.
105 * Returns: the passed udev library context if it has still an active reference, or #NULL otherwise.
107 _public_
struct udev
*udev_unref(struct udev
*udev
) {
111 assert(udev
->n_ref
> 0);
114 /* This is different from our convetion, but let's keep backward
115 * compatibility. So, do not use DEFINE_PUBLIC_TRIVIAL_UNREF_FUNC()
116 * macro to define this function. */
124 * @udev: udev library context
125 * @log_fn: function to be called for log messages
127 * This function is deprecated.
130 _public_
void udev_set_log_fn(
132 void (*log_fn
)(struct udev
*udev
,
133 int priority
, const char *file
, int line
, const char *fn
,
134 const char *format
, va_list args
)) {
139 * udev_get_log_priority:
140 * @udev: udev library context
142 * This function is deprecated.
145 _public_
int udev_get_log_priority(struct udev
*udev
) {
146 return log_get_max_level();
150 * udev_set_log_priority:
151 * @udev: udev library context
152 * @priority: the new log priority
154 * This function is deprecated.
157 _public_
void udev_set_log_priority(struct udev
*udev
, int priority
) {
158 log_set_max_level(priority
);