about summary refs log tree commit diff
path: root/shared/systemd/src/basic/format-util.c
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2019-12-18 18:30:31 +0100
committerMichael Biebl <biebl@debian.org>2019-12-18 18:30:31 +0100
commit4bde769dba8f804547ce1f5fcda731035d3d45f1 (patch)
tree3a4907fdbf4972fad5a036ef64ce643d704e8733 /shared/systemd/src/basic/format-util.c
parentbbf6329c27676323a899b7328575cc3f6c5f48cc (diff)
parent28028b26b3371756811e95d894f709f4b1207c00 (diff)
Update upstream source from tag 'upstream/1.22.0'
Update to upstream version '1.22.0'
with Debian dir a81ba1028908d08fc4866734c3df4a042bf9a511
Diffstat (limited to 'shared/systemd/src/basic/format-util.c')
-rw-r--r--shared/systemd/src/basic/format-util.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/shared/systemd/src/basic/format-util.c b/shared/systemd/src/basic/format-util.c
index 7a3e735b..62477f53 100644
--- a/shared/systemd/src/basic/format-util.c
+++ b/shared/systemd/src/basic/format-util.c
@@ -2,15 +2,26 @@
 
 #include "nm-sd-adapt-shared.h"
 
-#include <stdio.h>
-
 #include "format-util.h"
 #include "memory-util.h"
+#include "stdio-util.h"
 
-char *format_ifname(int ifindex, char buf[static IF_NAMESIZE + 1]) {
+assert_cc(DECIMAL_STR_MAX(int) + 1 <= IF_NAMESIZE + 1);
+char *format_ifname_full(int ifindex, char buf[static IF_NAMESIZE + 1], FormatIfnameFlag flag) {
         /* Buffer is always cleared */
         memzero(buf, IF_NAMESIZE + 1);
-        return if_indextoname(ifindex, buf);
+        if (if_indextoname(ifindex, buf))
+                return buf;
+
+        if (!FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX))
+                return NULL;
+
+        if (FLAGS_SET(flag, FORMAT_IFNAME_IFINDEX_WITH_PERCENT))
+                snprintf(buf, IF_NAMESIZE + 1, "%%%d", ifindex);
+        else
+                snprintf(buf, IF_NAMESIZE + 1, "%d", ifindex);
+
+        return buf;
 }
 
 char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) {