misc: Add grub_sprintf() C99/POSIX non-conformance comment
PATCH 1/1 misc: Add grub_sprintf() C99/POSIX non-conformance comment
Make clear that grub_sprintf() does not conform to C99/POSIX. It returns the number of bytes written, even when n is less than the length of the fully formatted string.
Signed-off-by Glenn Washburn <[email protected]>
--- grub-core/kern/misc.c | 9 +++++++++ 1 file changed, 9 insertions(+)
grub-core/kern/misc.c +9 -0
@@ -983,6 +983,7 @@ write_number (char *str, grub_size_t *count, grub_size_t max_len, grub_size_t fowrite_char (str, count, max_len, zerofill); } +/* See grub_snprintf for details of non-compliance to C99 and POSIX */ static int grub_vsnprintf_real (char *str,grub_size_t max_len,const char *fmt0,struct printf_args *args)
@@ -1204,6 +1205,14 @@ grub_vsnprintf (char *str, grub_size_t n, const char *fmt, va_list ap)return ret < n ? ret : n; } +/* +* Note: grub_snprintf does not conform to C99 nor the POSIX specs. +* Specifically, it returns the number of bytes written, minus the NULL +* byte. Whereas, the specs say that the return value should be the +* number of bytes that *would* be written if n were sufficiently large +* to contain the formatted output. This only matters when n is smaller +* than the formatted string. +*/ int grub_snprintf (char *str,grub_size_t n,const char *fmt, ...) {
Signature · 1 line
2.34.1