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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Wed, 11 Jul 2007, Carlos Rica wrote:

> @@ -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

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux