blob: 2a0b072df8f51178b098d77b43f71b42fcb5a922 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// SPDX-License-Identifier: LGPL-2.1+
#ifndef __NM_REF_STRING_H__
#define __NM_REF_STRING_H__
/*****************************************************************************/
typedef struct {
const char *const str;
const gsize len;
} NMRefString;
/*****************************************************************************/
NMRefString *nm_ref_string_new_len (const char *cstr, gsize len);
static inline NMRefString *
nm_ref_string_new (const char *cstr)
{
return cstr
? nm_ref_string_new_len (cstr, strlen (cstr))
: NULL;
}
NMRefString *nm_ref_string_ref (NMRefString *rstr);
void _nm_ref_string_unref_non_null (NMRefString *rstr);
static inline void
nm_ref_string_unref (NMRefString *rstr)
{
if (rstr)
_nm_ref_string_unref_non_null (rstr);
}
NM_AUTO_DEFINE_FCN_VOID0 (NMRefString *, _nm_auto_ref_string, _nm_ref_string_unref_non_null)
#define nm_auto_ref_string nm_auto(_nm_auto_ref_string)
/*****************************************************************************/
static inline const char *
nm_ref_string_get_str (NMRefString *rstr)
{
return rstr ? rstr->str : NULL;
}
static inline gsize
nm_ref_string_get_len (NMRefString *rstr)
{
return rstr ? rstr->len : 0u;
}
#endif /* __NM_REF_STRING_H__ */
|