diff options
author | Thomas Haller <thaller@redhat.com> | 2016-10-08 19:16:27 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-10-11 11:37:46 +0200 |
commit | 9ff1fa4ae1bb1d128058e33691cc215633a84f8c (patch) | |
tree | 276c8c77c4fc5920985037d42fe9efa84d310581 | |
parent | c5f4e36fd9147cfbb162383da857292727aab5ac (diff) | |
download | NetworkManager-9ff1fa4ae1bb1d128058e33691cc215633a84f8c.tar.gz |
shared: add NM_DECIMAL_STR_MAX() macro
-rw-r--r-- | shared/nm-utils/nm-macros-internal.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/shared/nm-utils/nm-macros-internal.h b/shared/nm-utils/nm-macros-internal.h index 8b7510973c..c072eef61a 100644 --- a/shared/nm-utils/nm-macros-internal.h +++ b/shared/nm-utils/nm-macros-internal.h @@ -615,6 +615,20 @@ nm_decode_version (guint version, guint *major, guint *minor, guint *micro) { } /*****************************************************************************/ +/* taken from systemd's DECIMAL_STR_MAX() + * + * Returns the number of chars needed to format variables of the + * specified type as a decimal string. Adds in extra space for a + * negative '-' prefix (hence works correctly on signed + * types). Includes space for the trailing NUL. */ +#define NM_DECIMAL_STR_MAX(type) \ + (2+(sizeof(type) <= 1 ? 3 : \ + sizeof(type) <= 2 ? 5 : \ + sizeof(type) <= 4 ? 10 : \ + sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)]))) + +/*****************************************************************************/ + /* if @str is NULL, return "(null)". Otherwise, allocate a buffer using * alloca() of size @bufsize and fill it with @str. @str will be quoted with * single quote, and in case @str is too long, the final quote will be '^'. */ |