git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git log doesn't allow %x00 in custom format anymore?

From
Jeff King <peff@peff.net>
Date
Oct 7, 2010, 18:13 UTC
Message-ID
<20101007181349.GD18518@sigill.intra.peff.net>
In-Reply-To
<AANLkTinu6fhd9DwfJpjiaxOUu_MrTym_RepR9f44=vrv@mail.gmail.com>
On Thu, Oct 07, 2010 at 08:05:20PM +0200, Erik Faye-Lund wrote:
Show 15 quoted lines
> >> I don't know which one would be most portable, but if fwrite is the
> >> problem, then
> >>
> >>   printf("%*s%c", buf.buf, buf.len, info->hdr_termination);
> >>
> >> should do the trick.
> >
> > It does work, but you have to cast the buf.len size_t to an int.
> >
> I'm not sure how portable it is, though. This is what K&R has to say
> on the matter: "characters from the string are printed until a ´\0´ is
> reached or until the number of characters indicated by the precision
> have been printed". To me it's not clear if that means that either
> cases can terminate the printing when the precision has been
> specified.

I take it back. It doesn't actually work (I thought I had done this just recently, but clearly not). Try:

  #include <stdio.h>
  int main()
  {
    char buf[] = "123456789";
    buf[2] = '\0';
    printf("%.*s\n", 5, buf);
    return 0;
  }
It prints just "12" for me.
-Peff
Previous: Erik Faye-LundNext: Erik Faye-Lund
Message 16 of 19 in “git log doesn't allow %x00 in custom format anymore?”
  1. Kirill LikhodedovOct 7, 2010
  2. Jeff KingOct 7, 2010
  3. Kirill LikhodedovOct 7, 2010
  4. Jeff KingOct 7, 2010
  5. Johannes SixtOct 7, 2010
  6. Kirill LikhodedovOct 7, 2010
  7. Jeff KingOct 7, 2010
  8. Matthieu MoyOct 7, 2010
  9. Drew NorthupOct 7, 2010
  10. Erik Faye-LundOct 7, 2010
  11. Erik Faye-LundOct 7, 2010
  12. Jeff KingOct 7, 2010
  13. Matthieu MoyOct 7, 2010
  14. Jeff KingOct 7, 2010
  15. Erik Faye-LundOct 7, 2010
  16. Jeff KingOct 7, 2010
  17. Erik Faye-LundOct 7, 2010
  18. Jeff KingOct 7, 2010
  19. Erik Faye-LundOct 7, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.