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

Re: [PATCH 1/2] Function stripspace now gets a buffer instead file descriptors.

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 11, 2007, 19:17 UTC
Message-ID
<Pine.LNX.4.64.0707112010560.4516@racer.site>
In-Reply-To
<4695267A.7080202@gmail.com>
Hi,
On Wed, 11 Jul 2007, Carlos Rica wrote:
Show 14 quoted lines
> @@ -28,52 +26,67 @@ static int cleanup(char *line, int len)
>   * Remove empty lines from the beginning and end
>   * and also trailing spaces from every line.
>   *
> + * Note that the buffer will not be null-terminated.
> + *
>   * Turn multiple consecutive empty lines between paragraphs
>   * into just one empty line.
>   *
>   * If the input has only empty lines and spaces,
>   * no output will be produced.
>   *
> + * If last line has a newline at the end, it will be removed.
> + *

Please let me comment about the rationale for both changes: The stripspace() function (which this hunk is about) is more useful if it does not allocate a new buffer, but works in-place.

And since it knows the new length already, it can just as well return the length, and _not_ NUL terminate (which would mean that we have to reallocate if we used read_pipe() to get the buffer).

The reason for the missing newline at the end is the same: since we accept buffers with a missing newline at the end, we would have to reallocate in that case.

So for the sake of simplicity, we neither NUL-terminate, nor \n terminate the buffer, and leave that to the callers.

Ciao, Dscho

Previous: Carlos RicaNext: Junio C Hamano
Message 2 of 7 in “Function stripspace now gets a buffer instead file descriptors.”
  1. 1/2 Function stripspace now gets a buffer instead file descriptors.Carlos Rica, Jul 11, 2007
  2. Johannes SchindelinJul 11, 2007
  3. Junio C HamanoJul 11, 2007
  4. Bill LearJul 11, 2007
  5. Carlos RicaJul 11, 2007
  6. Junio C HamanoJul 12, 2007
  7. Carlos RicaJul 12, 2007

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.