mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/6] lib: display_options: constify pointer to static size_human_readable buf
Date: Mon, 16 Jun 2025 09:16:30 +0200	[thread overview]
Message-ID: <20250616071634.811000-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20250616071634.811000-1-a.fatoum@barebox.org>

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@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




  reply	other threads:[~2025-06-16  7:24 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-16  7:16 [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Ahmad Fatoum
2025-06-16  7:16 ` Ahmad Fatoum [this message]
2025-06-16  7:16 ` [PATCH 3/6] commands: iomem: print human readable sizes by default Ahmad Fatoum
2025-06-16  7:16 ` [PATCH 4/6] commands: iomemport: support showing info for particular argument Ahmad Fatoum
2025-06-16  7:16 ` [PATCH 5/6] commands: iomem: add support for printing type/attributes Ahmad Fatoum
2025-06-16  7:16 ` [PATCH 6/6] efi: payload: iomem: populate resource type/attributes Ahmad Fatoum
2025-06-17  7:13 ` [PATCH 1/6] resource: mark normal memory as supporting being uncacheable Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250616071634.811000-2-a.fatoum@barebox.org \
    --to=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox