Enlightenment SVN wrote: > Log: > Add eina_strbuf_reset > > Function to reset the internal string, so we can reuse the allocated > mem. > Author: englebass > Date: 2010-02-06 13:43:22 -0800 (Sat, 06 Feb 2010) > New Revision: 45952 > > Modified: > trunk/eina/src/include/eina_strbuf.h trunk/eina/src/lib/eina_strbuf.c > > Modified: trunk/eina/src/include/eina_strbuf.h > =================================================================== > --- trunk/eina/src/include/eina_strbuf.h 2010-02-06 21:43:12 UTC (rev > 45951) > +++ trunk/eina/src/include/eina_strbuf.h 2010-02-06 21:43:22 UTC (rev > 45952) > @@ -9,6 +9,7 @@ > > EAPI Eina_Strbuf *eina_strbuf_new(void); > EAPI void eina_strbuf_free(Eina_Strbuf *buf) EINA_ARG_NONNULL(1); > +EAPI void eina_strbuf_reset(Eina_Strbuf *buf) EINA_ARG_NONNULL(1); > EAPI void eina_strbuf_append(Eina_Strbuf *buf, const char *str) > EINA_ARG_NONNULL(1, 2); > EAPI void eina_strbuf_append_escaped(Eina_Strbuf *buf, const char *str) > EINA_ARG_NONNULL(1, 2); > EAPI void eina_strbuf_append_n(Eina_Strbuf *buf, const char *str, unsigned > int maxlen) EINA_ARG_NONNULL(1, 2); > > Modified: trunk/eina/src/lib/eina_strbuf.c > =================================================================== > --- trunk/eina/src/lib/eina_strbuf.c 2010-02-06 21:43:12 UTC (rev 45951) > +++ trunk/eina/src/lib/eina_strbuf.c 2010-02-06 21:43:22 UTC (rev 45952) > @@ -86,6 +86,23 @@ > } > > /** > + * Reset a string buffer > + * @param buf the buffer to reset > + * > + * The buffer len is set to 0, no mem is free'd > + */ > +EAPI void > +eina_strbuf_reset(Eina_Strbuf *buf) > +{ > + EINA_MAGIC_CHECK_STRBUF(buf); > + buf->len = 0; > + buf->size = EINA_STRBUF_INIT_SIZE; > + buf->step = EINA_STRBUF_INIT_STEP; > + > + buf->buf[0] = '\0'; > +} >
If you don't change the actual buffer size, i.e. you are using realloc, you shouldn't change the saved buf->size. Regards Peter ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ enlightenment-devel mailing list enlightenment-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-devel