mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 19:40:12 +01:00
shared: add NM_DECIMAL_STR_MAX() macro
This commit is contained in:
parent
c5f4e36fd9
commit
9ff1fa4ae1
1 changed files with 14 additions and 0 deletions
|
|
@ -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 '^'. */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue