Hi Linus, On Mon, Jul 7, 2025 at 8:17 PM Linus Torvalds <torva...@linux-foundation.org> wrote: > > On Sun, 6 Jul 2025 at 22:06, Alejandro Colomar <a...@kernel.org> wrote: > > > > - p += snprintf(p, ID_STR_LENGTH - (p - name), "%07u", s->size); > > + p = seprintf(p, e, "%07u", s->size); > > I am *really* not a fan of introducing yet another random non-standard > string function. > > This 'seprintf' thing really seems to be a completely made-up thing. > Let's not go there. It just adds more confusion - it may be a simpler > interface, but it's another cogniitive load thing, and honestly, that > "beginning and end" interface is not great. > > I think we'd be better off with real "character buffer" interfaces, > and they should be *named* that way, not be yet another "random > character added to the printf family".
I was really interested to see this comment because I presented a design for a standard character buffer interface, "strb_t", to WG14 in summer of 2014. The latest published version of that paper is https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3306.pdf (very long) and the slides (which cover most of the important points) are https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3276.pdf I contacted you beforehand, for permission to include kasprintf and kvasprintf in the 'prior art' section of my paper. At the time, you gave me useful information about the history of those and related functions. (As an aside, Alejandro has since written a proposal to standardise a similar function named aprintf, which I support: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3630.txt ) Going back to "strb_t", I did not bother you about it again because I didn't anticipate it being used in kernel space, which has its own interfaces for most things. I'd be interested to hear what you think of it though. My intent was to make it impossible to abuse, insofar as that is possible. That led me to make choices (such as use of an incomplete struct type) that some might consider strange or overengineered. I didn't see the point in trying to replace one set of error-prone functions with another. Alejandro has put a lot of thought into his proposed seprintf function, but it still fundamentally relies on the programmer passing the right arguments and it doesn't seem to extend the functionality of snprintf in any way that I actually need. For example, some of my goals for the character buffer interface were: - A buffer should be specified using a single parameter. - Impossible to accidentally shallow-copy a buffer instead of copying a reference to it. - No aspect of character consumption delegated to character producers, e.g.: * whether to insert or overwrite. * whether to prepend, insert or append. * whether to allocate extra storage, and how to do that. - Minimize the effect of ignoring return values and not require ubiquitous error-handling. - Able to put strings directly into a buffer from any source. - Allow diverse implementations (mostly to allow tailoring to different platforms). This small program demonstrates some of those ideas: https://godbolt.org/z/66Gnre6dx It uses my ugly hacked-together prototype. Chris