Xenomai  3.1
ancillaries.h
1 /*
2  * Copyright (C) 2014 Philippe Gerum <rpm@xenomai.org>.
3  *
4  * Xenomai is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published
6  * by the Free Software Foundation; either version 2 of the License,
7  * or (at your option) any later version.
8  *
9  * Xenomai is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with Xenomai; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17  * 02111-1307, USA.
18  */
19 #ifndef _COBALT_KERNEL_ANCILLARIES_H
20 #define _COBALT_KERNEL_ANCILLARIES_H
21 
22 #include <linux/kernel.h>
23 #include <linux/string.h>
24 #include <linux/uidgid.h>
25 #include <cobalt/uapi/kernel/limits.h>
26 
27 #define ksformat(__dst, __len, __fmt, __args...) \
28  ({ \
29  size_t __ret; \
30  __ret = snprintf(__dst, __len, __fmt, ##__args); \
31  if (__ret >= __len) \
32  __dst[__len-1] = '\0'; \
33  __ret; \
34  })
35 
36 #define kasformat(__fmt, __args...) \
37  ({ \
38  kasprintf(GFP_KERNEL, __fmt, ##__args); \
39  })
40 
41 #define kvsformat(__dst, __len, __fmt, __ap) \
42  ({ \
43  size_t __ret; \
44  __ret = vsnprintf(__dst, __len, __fmt, __ap); \
45  if (__ret >= __len) \
46  __dst[__len-1] = '\0'; \
47  __ret; \
48  })
49 
50 #define kvasformat(__fmt, __ap) \
51  ({ \
52  kvasprintf(GFP_KERNEL, __fmt, __ap); \
53  })
54 
55 void __knamecpy_requires_character_array_as_destination(void);
56 
57 #define knamecpy(__dst, __src) \
58  ({ \
59  if (!__builtin_types_compatible_p(typeof(__dst), char[])) \
60  __knamecpy_requires_character_array_as_destination(); \
61  strncpy((__dst), __src, sizeof(__dst)); \
62  __dst[sizeof(__dst) - 1] = '\0'; \
63  __dst; \
64  })
65 
66 #define get_current_uuid() from_kuid_munged(current_user_ns(), current_uid())
67 
68 #endif /* !_COBALT_KERNEL_ANCILLARIES_H */