[PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf

Ahmad Fatoum a.fatoum at barebox.org
Mon Jun 16 00:16:30 PDT 2025


The function returns a pointer to a statically allocated buffer
that's formatted with the string representation of the size.

It's a bad idea to modify it from the outside, so reflect that in the
type system.

Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
 include/stdio.h       | 2 +-
 lib/display_options.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/stdio.h b/include/stdio.h
index 50688feff4e6..dcaed71dae05 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -97,7 +97,7 @@ static inline void ctrlc_handled(void)
 
 #endif
 
-char *size_human_readable(unsigned long long size);
+const char *size_human_readable(unsigned long long size);
 int readline(const char *prompt, char *buf, int len);
 
 #if (IN_PROPER && !defined(CONFIG_CONSOLE_NONE)) || \
diff --git a/lib/display_options.c b/lib/display_options.c
index d392deef0a78..b6b913310603 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -21,7 +21,7 @@
  *"as xxx KiB", "xxx.y KiB", "xxx MiB", "xxx.y MiB",
  * xxx GiB, xxx.y GiB, etc as needed;
  */
-char *size_human_readable(unsigned long long size)
+const char *size_human_readable(unsigned long long size)
 {
 	static char buf[30];
 	unsigned long m = 0, n;
-- 
2.39.5




More information about the barebox mailing list