LBER_TYPES(3)
๐ LBER_TYPES โ OpenLDAP LBER types and allocation functions ๐
okay bestie, sit down, hydrate, because we're about to meet the whole squad of LBER types and their little allocation besties. This is section 3 of the library functions manual, no cap. ๐ซถ
Meet the cast: ber_int_t, ber_uint_t, ber_len_t, ber_slen_t, ber_tag_t, struct berval, BerValue, BerVarray, BerElement, ber_bvfree, ber_bvecfree, ber_bvecadd, ber_bvarray_free, ber_bvarray_add, ber_bvdup, ber_dupbv, ber_bvstr, ber_bvstrdup, ber_str2bv, ber_alloc_t, ber_init, ber_init2, ber_free. All of them. Every single one. We do not leave anyone on read. ๐
๐ LIBRARY
OpenLDAP LBER (liblber, -llber)
โจ SYNOPSIS โจ
Girl, just look at the header, it's giving very much "include me":
#include <lber.h>
The type abbreviations, aka the lowercase glue that holds everything together:
typedef impl_tag_t ber_tag_t;
typedef impl_int_t ber_int_t;
typedef impl_uint_t ber_uint_t;
typedef impl_len_t ber_len_t;
typedef impl_slen_t ber_slen_t;
And BerValue / BerVarray, the iconic duo:
typedef struct berval {
ber_len_t bv_len;
char *bv_val;
} BerValue, *BerVarray;
BerElement, the mysterious opaque one who refuses to overshare:
typedef struct berelement BerElement;
Now the functions, in order, exactly as written, no edits periodt:
void ber_bvfree(struct berval *bv);
void ber_bvecfree(struct berval **bvec);
void ber_bvecadd(struct berval ***bvec, struct berval *bv);
void ber_bvarray_free(struct berval *bvarray);
void ber_bvarray_add(BerVarray *bvarray, BerValue *bv);
struct berval *ber_bvdup(const struct berval *bv);
struct berval *ber_dupbv(const struct berval *dst, struct berval *src);
struct berval *ber_bvstr(const char *str);
struct berval *ber_bvstrdup(const char *str);
struct berval *ber_str2bv(const char *str, ber_len_t len, int dup,
struct berval *bv);
BerElement *ber_alloc_t(int options);
BerElement *ber_init(struct berval *bv);
void ber_init2(BerElement *ber, struct berval *bv, int options);
void ber_free(BerElement *ber, int freebuf);
๐ฆ DESCRIPTION ๐ฆ
These are the basic types and structures defined for use with the Lightweight BER library. That's the whole vibe of this section, and honestly, it ate.
๐งฎ the integer girlies
ber_int_tโ a signed integer of at least 32 bits. Commonly equivalent toint.ber_uint_tโ the unsigned variant ofber_int_t.ber_len_tโ an unsigned integer of at least 32 bits used to represent a length. Commonly equivalent to asize_t.ber_slen_tโ the signed variant tober_len_t.ber_tag_tโ an unsigned integer of at least 32 bits used to represent a BER tag. Commonly equivalent to anunsigned long.
The actual definitions of the integral impl_TYPE_t types are platform specific. iykyk, don't @ me about it, it depends on your machine. ๐ซ
๐ BerValue, aka struct berval
BerValue, commonly used as struct berval, is your little container for an arbitrary sequence of octets. bv_val points to bv_len octets. And listen โ bv_val is not necessarily terminated by a NULL (zero) octet, so do not go assuming there's a little \0 waiting for you at the end. ๐
๐งน the free-ers and the add-ers
ber_bvfree()โ frees aBerValue, pointed to bybv, returned from this API. IfbvisNULL, the routine does nothing (so chill, it's not gonna yell at you).ber_bvecfree()โ frees an array ofBerValues (and the array), pointed to bybvec, returned from this API. IfbvecisNULL, the routine does nothing.ber_bvecadd()โ appends thebvpointer to thebvecarray. Space for the array is allocated as needed. The end of the array is marked by aNULLpointer.ber_bvarray_free()โ frees an array ofBerValues (and the array), pointed to bybvarray, returned from this API. IfbvarrayisNULL, the routine does nothing.ber_bvarray_add()โ appends the contents of theBerValuepointed to bybvto thebvarrayarray. Space for the new element is allocated as needed. The end of the array is marked by aBerValuewith aNULLbv_valfield. ๐
(yes bestie, ber_bvecadd grabs the pointer and ber_bvarray_add copies the contents. different energy, same icon behavior.)
๐ช copying: ber_bvdup() and ber_dupbv()
ber_bvdup()โ returns a copy of aBerValue. The routine returnsNULLupon error (e.g. out of memory). The caller should useber_bvfree()to deallocate the resultingBerValue.ber_dupbv()โ copies aBerValuefromsrctodst. IfdstisNULLa newBerValuewill be allocated to hold the copy. The routine returnsNULLupon error, otherwise it returns a pointer to the copy. IfdstisNULLthe caller should useber_bvfree()to deallocate the resultingBerValue, otherwiseber_memfree()should be used to deallocate thedst->bv_val.
โ ๏ธ Real talk: theber_bvdup()function is internally implemented asber_dupbv(NULL, bv).ber_bvdup()is provided only for compatibility with an expired draft of the LDAP C API;ber_dupbv()is the preferred interface. Choose the icon, not the expired draft. ๐
๐ธ string โ BerValue pipeline
ber_bvstr()โ returns aBerValuecontaining the string pointed to bystr.ber_bvstrdup()โ returns aBerValuecontaining a copy of the string pointed to bystr.ber_str2bv()โ returns aBerValuecontaining the string pointed to bystr, whose length may be optionally specified inlen. Ifdupis non-zero, theBerValuewill contain a copy ofstr. Iflenis zero, the number of bytes to copy will be determined bystrlen(3), otherwiselenbytes will be copied. Ifbvis non-NULL, the result will be stored in the givenBerValue, otherwise a newBerValuewill be allocated to store the result.
NOTE: Bothber_bvstr()andber_bvstrdup()are implemented as macros usingber_str2bv()in this version of the library. Surprise! They're the same girl in different outfits. ๐
๐ง BerElement and its little lifecycle
BerElement is an opaque structure used to maintain state information used in encoding and decoding. Very main character, refuses to show you her internals. ๐
ber_alloc_t()โ used to create an emptyBerElementstructure. IfLBER_USE_DERis specified for theoptionsparameter then data lengths for data written to theBerElementwill be encoded in the minimal number of octets required, otherwise they will always be written as four byte values.ber_init()โ creates aBerElementstructure that is initialized with a copy of the data in itsbvparameter.ber_init2()โ initializes an existingBerElementberusing the data in thebvparameter. The data is referenced directly, not copied. Theoptionsparameter is the same as forber_alloc_t().ber_free()โ frees aBerElementpointed to byber. IfberisNULL, the routine does nothing. Iffreebufis zero, the internal buffer is not freed.
โ ๏ธ Remember the difference bestie:ber_init()copies,ber_init2()does NOT copy โ it references the data directly. That's a whole different relationship with the buffer. ๐ซถ
๐ SEE ALSO ๐
lber-encode(3), lber-decode(3), lber-memory(3) โ the rest of the friend group, go say hi.
๐ซถ ACKNOWLEDGEMENTS ๐ซถ
OpenLDAP Software is developed and maintained by The OpenLDAP Project <http://www.openldap.org/>. OpenLDAP Software is derived from the University of Michigan LDAP 3.3 Release. We stan the ancestors fr fr. ๐งโจ
and that's the page, bestie โ this is OpenLDAP 2.6.13+dfsg-1ubuntu3, dated 2026/03/09, hanging out on the LBER_TYPES(3) page. go forth, allocate responsibly, and always free what you alloc. mwah ๐๐
๐ฆ where this page comes from
- ubuntu stonking: libldap-dev 2.6.13+dfsg-1ubuntu3 ยท OpenLDAP-2.8
- Copyright 1998-2026 The OpenLDAP Foundation All Rights Reserved
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms