mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-07 05:30:17 +01:00
nmtst: add functions nmtst_static_SIZE_NUM() to create a copy of a string returned from an internal buffer
Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
parent
5a58afcec9
commit
be56b26c7d
1 changed files with 20 additions and 0 deletions
|
|
@ -242,6 +242,26 @@ nmtst_get_rand ()
|
|||
return __nmtst_internal.rand;
|
||||
}
|
||||
|
||||
|
||||
#define __define_nmtst_static(NUM,SIZE) \
|
||||
inline static const char * \
|
||||
nmtst_static_##SIZE##_##NUM (const char *str) \
|
||||
{ \
|
||||
gsize l; \
|
||||
static char buf[SIZE]; \
|
||||
\
|
||||
if (!str) \
|
||||
return NULL; \
|
||||
l = g_strlcpy (buf, str, sizeof (buf)); \
|
||||
g_assert (l < sizeof (buf)); \
|
||||
return buf; \
|
||||
}
|
||||
__define_nmtst_static(01, 1024)
|
||||
__define_nmtst_static(02, 1024)
|
||||
__define_nmtst_static(03, 1024)
|
||||
#undef __define_nmtst_static
|
||||
|
||||
|
||||
#define NMTST_SWAP(x,y) \
|
||||
G_STMT_START { \
|
||||
char __nmtst_swap_temp[sizeof(x) == sizeof(y) ? (signed) sizeof(x) : -1]; \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue