[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string buffer
From: |
Bruno Haible |
Subject: |
Re: string buffer |
Date: |
Sun, 17 Jun 2012 18:45:01 +0200 |
User-agent: |
KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; ) |
Pádraig Brady wrote:
> Since there are lots of appending of strings here,
> the approach taken in coreutils so far was
> to append in a large buffer allocated up front,
> or just to write to stdout.
>
> I guess something in between is more appropriate for a lib.
> I.E. efficiently append to a string on the heap.
> This is a common operation, so maybe there are routines
> in gnulib to use for this? I previously abstracted this operation in:
> http://www.pixelbeat.org/libs/sbuf.h
> http://www.pixelbeat.org/libs/sbuf.c
In gnulib, we have mostly inlined such operations so far. If you want
to add a module 'stringbuffer', similar to the module 'linebuffer' which
we already have and which is for input, please do. This is welcome.
Back to the function that returns a relativized file name. There are
basically 3-4 common return value conventions for functions that need to
return a string.
- Return a 'char *', to a statically allocated area. (Ex.: strerror)
- Return a 'char *', freshly allocated. (Ex.: asprintf)
- Pass a buffer and its length. (Ex.: gethostname)
- Pass a buffer and a pointer to a length location. (Ex.: unistr.h)
I think some of these will also work in combination with a 'stringbuffer',
without the need to have an interface that takes a 'string_buffer *' as
argument.
I wouldn't like to see 'filename-relative' have a dependency on 'stringbuffer',
when so many functions who produce a string don't have this dependency.
Bruno
Re: new module: relpath, Akim Demaille, 2012/06/18
Re: new module: relpath, Eli Zaretskii, 2012/06/18