Debian Codegraph @

pam/pam_fprintd_autoptrs.h

raw symbols SCIP
1 /*
2 * pam_fprint: PAM module for fingerprint authentication through fprintd
3 * Copyright (C) 2020 Marco Trevisan <[email protected]>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include <stdlib.h>
23
24 /* Define auto-pointers functions, based on GLib Macros */
25
26 #define _CLEANUP_FUNC(func) __attribute__((cleanup (func)))
27
28 #define _PF_AUTOPTR_FUNC_NAME(TypeName) pf_autoptr_cleanup_ ## TypeName
29 #define _PF_AUTOPTR_TYPENAME(TypeName) TypeName ## _pf_autoptr
30
31 #define PF_DEFINE_AUTOPTR_CLEANUP_FUNC(TypeName, cleanup) \
32 typedef TypeName *_PF_AUTOPTR_TYPENAME (TypeName); \
33 static __attribute__((__unused__)) inline void \
34 _PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName **_ptr) \
35 { if (_ptr) (cleanup) (*_ptr); }
36
37 #define PF_DEFINE_AUTO_CLEAN_FUNC(TypeName, cleanup) \
38 static __attribute__((__unused__)) inline void \
39 _PF_AUTOPTR_FUNC_NAME (TypeName) (TypeName *_ptr) \
40 { cleanup (_ptr); }
41
42 static inline void
43 autoptr_cleanup_generic_free (void *p)
44 {
45 void **pp = (void **) p;
46
47 free (*pp);
48 }
49
50 #define pf_autofree _CLEANUP_FUNC (autoptr_cleanup_generic_free)
51 #define pf_autoptr(TypeName) \
52 _CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) \
53 _PF_AUTOPTR_TYPENAME (TypeName)
54 #define pf_auto(TypeName) \
55 _CLEANUP_FUNC (_PF_AUTOPTR_FUNC_NAME (TypeName)) TypeName
56
57 PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus, sd_bus_unref)
58 PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus_message, sd_bus_message_unref)
59 PF_DEFINE_AUTOPTR_CLEANUP_FUNC (sd_bus_slot, sd_bus_slot_unref)
60
61 PF_DEFINE_AUTO_CLEAN_FUNC (sd_bus_error, sd_bus_error_free)