Skip to contentSkip to conversation

libbpf: Use PRIu64 when printing ulimit value

PATCH In review Toke Høiland-Jørgensen 2 participants 2 messages Dec 18, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libbpf: Use PRIu64 when printing ulimit value

Naresh pointed out that libbpf builds fail on 32-bit architectures because rlimit.rlim_cur is defined as 'unsigned long long' on those architectures. Fix this by using the PRIu64 definition in printf.

Fixes dc3a2d254782 ("libbpf: Print hint about ulimit when getting permission denied error")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +1 -1
index 3fe42d6b0c2f..ba31083998ce 100644
@@ -117,7 +117,7 @@ static void pr_perm_msg(int err)
 		return;
 
 	if (limit.rlim_cur < 1024)
-		snprintf(buf, sizeof(buf), "%lu bytes", limit.rlim_cur);
+		snprintf(buf, sizeof(buf), "%"PRIu64" bytes", limit.rlim_cur);
 	else if (limit.rlim_cur < 1024*1024)
 		snprintf(buf, sizeof(buf), "%.1f KiB", (double)limit.rlim_cur / 1024);
 	else
Signature · 1 line
2.24.1
#1 lore raw
Quoted 17 lines · Toke Høiland-Jørgensen

Naresh pointed out that libbpf builds fail on 32-bit architectures because rlimit.rlim_cur is defined as 'unsigned long long' on those architectures. Fix this by using the PRIu64 definition in printf.

Fixes dc3a2d254782 ("libbpf: Print hint about ulimit when getting permission denied error")
---
 tools/lib/bpf/libbpf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/lib/bpf/libbpf.c +0 -0
index 3fe42d6b0c2f..ba31083998ce 100644

tools/lib/bpf/libbpf.c static void pr_perm_msg(int err) · line 120

Quoted 5 lines
tools/lib/bpf/libbpf.c +1 -1
@@ -117,7 +117,7 @@ static void pr_perm_msg(int err)
                return;
 
        if (limit.rlim_cur < 1024)
-               snprintf(buf, sizeof(buf), "%lu bytes", limit.rlim_cur);
+               snprintf(buf, sizeof(buf), "%"PRIu64" bytes", limit.rlim_cur);

please use %zu and (size_t) cast like the rest of libbpf. Thanks!