Re: svn commit: r1917047 - in /apr/apr/trunk: CHANGES buffer/ buffer/apr_buffer.c build.conf include/apr_buffer.h test/Makefile.in test/Makefile.win test/NWGNUaprtest test/abts_tests.h test/testbuffer.c test/testutil.h
Ruediger Pluem <[email protected]> Thu, 29 Aug 2024 20:46:12 +0200
| Newsgroups | gmane.comp.apache.apr.devel |
|---|---|
| Message-ID | <[email protected]> |
On 4/16/24 10:54 PM, [email protected] wrote: > Author: minfrin > Date: Tue Apr 16 20:54:51 2024 > New Revision: 1917047 > > URL: http://svn.apache.org/viewvc?rev=1917047&view=rev > Log: > Add the apr_buffer API. > > An APR buffer is a structure that can contain a zero terminated string, or > a non zero terminated block of memory, and allow such structures to be > passed around and handled in a memory efficient way. > > We allow two buffers to be compared without duplicating strings. Memory > buffers can be converted to string buffers safely. The contents of buffers > can be copied into and out of other systems like caches using memory > allocation callbacks. > > Used by the new LDAP API, where string support has been deprecated in > favour of fixed sized buffers. > > Added: > apr/apr/trunk/buffer/ > apr/apr/trunk/buffer/apr_buffer.c (with props) > apr/apr/trunk/include/apr_buffer.h (with props) > apr/apr/trunk/test/testbuffer.c (with props) > Modified: > apr/apr/trunk/CHANGES > apr/apr/trunk/build.conf > apr/apr/trunk/test/Makefile.in > apr/apr/trunk/test/Makefile.win > apr/apr/trunk/test/NWGNUaprtest > apr/apr/trunk/test/abts_tests.h > apr/apr/trunk/test/testutil.h > > Added: apr/apr/trunk/buffer/apr_buffer.c > URL: http://svn.apache.org/viewvc/apr/apr/trunk/buffer/apr_buffer.c?rev=1917047&view=auto > ============================================================================== > --- apr/apr/trunk/buffer/apr_buffer.c (added) > +++ apr/apr/trunk/buffer/apr_buffer.c Tue Apr 16 20:54:51 2024 > @@ -0,0 +1,408 @@ > +APR_DECLARE(char *) apr_buffer_pstrncat(apr_pool_t *p, const apr_buffer_t *buf, > + int nelts, const char *sep, int flags, > + apr_size_t *nbytes) > +{ > + const apr_buffer_t *src = buf; > + apr_size_t seplen = sep ? strlen(sep) : 0; > + apr_size_t size = 0; > + > + char *dst, *str; > + > + int i; > + for (i = 0; i < nelts; i++) { > + > + if (i > 0) { > + size += seplen; > + } > + > + if (src->size < 0) { > + size += (-src->size) - 1; > + } > + else { > + if (APR_BUFFER_NONE == flags) { > + size += src->size; > + } > + else if (APR_BUFFER_BASE64 == flags) { > + apr_size_t b64len; > + > + if (APR_SUCCESS != apr_encode_base64(NULL, src->d.mem, src->size, > + APR_ENCODE_NONE, &b64len)) { > + return NULL; > + } > + size += b64len - 1; > + } > + } > + > + src++; > + } > + > + if (nbytes) { > + *nbytes = size; > + } > + > + str = dst = apr_palloc(p, size + 1); > + > + src = buf; > + > + for (i = 0; i < nelts; i++) { > + > + if (i > 0 && sep) { > + strncpy(dst, sep, seplen); > + dst += seplen; > + } > + > + if (src->size < 0) { > + strncpy(dst, src->d.str, (-src->size) - 1); > + dst += (-src->size) - 1; > + } > + else { > + if (APR_BUFFER_NONE == flags) { > + memcpy(dst, src->d.mem, src->size); Don't we miss a dst += src->size; here? > + } > + else if (APR_BUFFER_BASE64 == flags) { > + apr_size_t b64len; > + > + if (APR_SUCCESS != apr_encode_base64(dst, src->d.mem, src->size, > + APR_ENCODE_NONE, &b64len)) { > + return NULL; > + } > + dst += b64len; > + } > + } > + > + src++; > + } > + > + dst[0] = 0; > + > + return str; > +} > + > Regards RĂ¼diger