On 15/06/2021 08.48, Justin He wrote:
Hi Petr
quoted
quoted
+ /* no filling space at all */
+ if (buf >= end || !buf)
+ return buf + reserved_size;
+
+ /* small space for long name */
+ if (buf < end && prepend_len < 0)
+ return string_truncate(buf, end, p, dpath_len, spec);
We need this only because we allowed to write the path behind
spec.field_width. Do I get it right?
Both of field_width and precision:
"%.14pD" or "%8.14pD"
Precision is never gonna be used with %p (or any of its kernel
extensions) because gcc would tell you
foo.c:5:13: warning: precision used with ‘%p’ gnu_printf format [-Wformat=]
5 | printf("%.5p\n", foo);
and there's no way -Wformat is going to be turned off to allow that usage.
IOW, there's no need to add complexity to make "%.3pD" of something that
would normally print "/foo/bar" merely print "/fo", similar to what a
precision with %s would mean.
As for field width, I don't know if it's worth honouring, but IIRC the
original %pd and %pD did that (that's where we have widen_string etc. from).
Other %p extensions put the field with to some other use (e.g. the
bitmap and hex string printing), so they obviously cannot simultaneously
use it in the traditional sense.
Rasmus