Vstr documentation -- functions (345)

Index of sections

Index of sections, and their contents

Library initialization and exit functions

Function: vstr_init()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Nothing
Type[1]: void
Explanation:

This function needs to be called before any of the other functions are called.

Note:

The function can be called multiple times, without any problems.

Function: vstr_exit()
Returns: Nothing
Type: void
Parameter[1]: Nothing
Type[1]: void
Explanation:

This function can be called before exit, after all vstr objects have been freed, to cleanup data allocated internally in the Vstr library.

Note:

The function isn't needed but helps make sure there are no memory leaks, when used with a memory checker (or with the internal memory checker in the debug build).

Exporting data functions

Function: vstr_export_cstr_ptr()
Returns: A pointer to an array of characters, terminated by NIL
Type: const char *
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr
Type[2]: size_t
Parameter[3]: Length from position in the Vstr
Type[3]: size_t
Explanation:

This function is used to export a pointer to an array of characters of length (Parameter[3] + 1), the last byte will be a 0 to terminate the "C string".

Multiple adjacent calls will return the same pointer.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return NULL if it needs to allocate memory and cannot do so.

Note:

If you alter the Vstr in anyway then the returned pointer may point to free()'d memory. To get a reference to this data use vstr_export_cstr_ref() instead.

This data needs to be cached in the Vstr string, and so can only work if the Vstr string has the ability to cache data (see VSTR_CNTL_BASE_GET_FLAG_HAVE_CACHE). If you want to make sure that the cached data is gone from the Vstr string, cache then you can call vstr_cache_cb_free() on the cookie from "/vstr__/cstr".

Any _NON data in the Vstr will be uninitialized data in the "C string".

If there are any 0 bytes in the Vstr they will make the string look shorter than it really is to normal C style string functions.

Function: vstr_export_cstr_malloc()
Returns: A malloc'd pointer to an array of characters, terminated by NIL
Type: char *
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr
Type[2]: size_t
Parameter[3]: Length from position in the Vstr
Type[3]: size_t
Explanation:

This function is used to export a malloc'd pointer to an array of characters of length (Parameter[3] + 1), the last byte will be a 0 to terminate the "C string". You will need to pass the pointer to free(), when you are done with it.

Each call will return a different pointer.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return NULL if it needs to allocate memory and cannot do so.

Note:

Any _NON data in the Vstr will be uninitialized data in the "C string".

If there are any 0 bytes in the Vstr they will make the string look shorter than it really is to normal C/POSIX string functions.

Function: vstr_export_cstr_buf()
Returns: Nothing
Type: void
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr
Type[2]: size_t
Parameter[3]: Length from position in the Vstr
Type[3]: size_t
Parameter[4]: Data array to export to
Type[4]: void *
Parameter[5]: Length of data (Parameter[4])
Type[5]: size_t
Explanation:

This function is used to export a copy of the data in the Vstr string to a data array, the maximum amount of data stored in the array will be of length (Parameter[3] + 1), the last byte will be a 0 to terminate the "C string". However the data before the terminator of the "C string" is limited to (Parameter[5] - 1).

Note:

Data from nodes of type NON are exported by not doing anything to the underlying data array (Ie. It'll have whatever data was in there to start with).

If there are any 0 bytes in the Vstr they will make the "C string" look shorter than it really is to normal C/POSIX string functions.

Function: vstr_export_cstr_ref()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr
Type[2]: size_t
Parameter[3]: Length from position in the Vstr
Type[3]: size_t
Parameter[4]: Offset of Vstr memory reference (Return)
Type[4]: size_t *
Explanation:

This function is used to return a pointer to a Vstr memory reference of at least length (Parameter[3] + 1), the last byte will be a 0 to terminate the "C string" stored in (Vstr_ref *)->ptr. The offset (Parameter[4]) should be used to find the beginning of the block of memory to use.

When you are finished with the reference you need to use vstr_ref_del() or the memory will stay allocated forever.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return NULL if it needs to allocate memory and cannot do so.

Note:

If you want to make sure that the cached data is gone from the Vstr string, cache then you can call vstr_cache_cb_free() on the cookie from "/vstr__/cstr".

Any _NON data in the Vstr will be uninitialized data in the "C string".

If there are any 0 bytes in the Vstr they will make the string look shorter than it really is to normal C/POSIX string functions.

Function: vstr_export_iovec_ptr_all()
Returns: Size of bytes in the Vstr string
Type: size_t
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Returns the start of the iovec array
Type[2]: struct iovec **
Parameter[2]: Returns the number of iovec structures in the array
Type[2]: unsigned int *
Explanation:

This function is used to export a pointer to an array of iovec structures this can then be passed directly to writev() etc. or just used to quickly access the data in the Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so.

Note:

Nodes of type NON are represented by a iov_base set to NULL.

Altering the iov_base/iov_len members will probably do very bad things, if you need to do this use the vstr_export_iovec_cpy_ptr()

Altering the data in the iovec structure isn't a good idea as it isn't easy for the programer to know if the data is shared/read-only. If you need to do this you should use either the vstr_sub_* functions instead or vstr_export_iovec_cpy_buf() (the later does a copy). However if you do alter the data then you'll need to do vstr_cache_cb_sub().

Either of the pointers for the iovec array (Parameter[2]) or the number of iovecs (Parameter[3]) can be the NULL pointer, in which case nothing will be written to those pointers.

Function: vstr_export_iovec_cpy_buf()
Returns: Size of bytes exported from the Vstr string
Type: size_t
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Pointer to array of initialized iovec structures
Type[4]: struct iovec *
Parameter[5]: Number of iovec structures (Parameter[4])
Type[5]: unsigned int
Parameter[6]: Returns the number of iovec structures used in the array
Type[6]: unsigned int *
Explanation:

This function is used to export a copy of the data in the Vstr string to an array of iovec structures this can then be passed directly to writev() (or even a readv() although that wouldn't often be useful) etc.

Think of this function as doing a readv() from a Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

Note:

Data from nodes of type NON are exported by not doing anything to the underlying iov_base data arrays (Ie. It'll have whatever data was in there to start with).

The length returned may be shorter than that given as Parameter[3], as it's the number of bytes copied into the iov_base arrays in the iovec structures.

Function: vstr_export_iovec_cpy_ptr()
Returns: Size of bytes exported from the Vstr string
Type: size_t
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Pointer to array of iovec structures
Type[4]: struct iovec *
Parameter[5]: Number of iovec structures (Parameter[4])
Type[5]: unsigned int
Parameter[6]: Returns the number of iovec structures used in the array
Type[6]: unsigned int *
Explanation:

This function is used to export a set of pointer/length pairs to the data specified in the Vstr string, this can then be passed directly to writev() etc.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

Note:

Nodes of type NON are represented by a iov_base set to NULL.

Altering the data in the iovec structure isn't a good idea as it isn't easy for the programer to know if the data is shared/read-only. If you need to do this you should use either the vstr_sub_* functions instead or vstr_export_iovec_cpy_buf() (the later does a copy).

Function: vstr_export_buf()
Returns: Size of bytes exported from the Vstr string
Type: size_t
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Data array to export to
Type[4]: void *
Parameter[5]: Length of data (Parameter[4])
Type[5]: size_t
Explanation:

This function is used to export a copy of the data in the Vstr string to a data array.

Think of this function as doing a read() from a Vstr string. However the data will be limited to the minimum of the length of the vstr (Parameter[3]) and the length of the data (Parameter[5]).

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

Note:

Data from nodes of type NON are exported by not doing anything to the underlying data array (Ie. It'll have whatever data was in there to start with).

Function: vstr_export_chr()
Returns: Character exported from the Vstr string
Type: char
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Position in the Vstr string (Parameter[1])
Type[2]: size_t
Explanation:

This function is used to return a character at a certain position in a Vstr string.

Note:

It is impossible to distinguish between an error, data from a NON node and real data that is equal to the value 0.

Function: vstr_export_ref()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Start position in the Vstr
Type[2]: size_t
Parameter[3]: Length from position in the Vstr
Type[3]: size_t
Parameter[4]: Offset of Vstr memory reference (Return)
Type[4]: size_t *
Explanation:

This function is used to return a pointer to a Vstr memory reference of at least length (Parameter[3]). The offset (Parameter[4]) should be used to find the beginning of the block of memory to use.

When you are finished with the reference you need to use vstr_ref_del() or the memory will stay allocated forever.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return NULL if it needs to allocate memory and cannot do so.

Note:

Any _NON data in the Vstr will be uninitialized data in the memory pointed to by the memory reference.

Memory reference functions

Function: vstr_ref_add()
Returns: Vstr memory reference (Parameter[1])
Type: struct Vstr_ref *
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This function will add a reference count to the Vstr_ref (Parameter[1]).

Function: vstr_ref_del() Returns:
Type: void
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This function will delete a reference count from the Vstr_ref (Parameter[1]), when the reference count reaches zero then the cleanup function will be called.

Function: vstr_ref_cb_free_nothing()
Returns: Nothing
Type: void
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This function does nothing.

Function: vstr_ref_cb_free_ref()
Returns: Nothing
Type: void
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This will call free() on the Vstr_ref (Parameter[1]).

Function: vstr_ref_cb_free_ptr()
Returns: Nothing
Type: void
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This will call free() on the data in the Vstr_ref (Parameter[1])->ptr (unless the passed reference is the NULL pointer, then it does nothing).

Function: vstr_ref_cb_free_ptr_ref()
Returns: Nothing
Type: void
Parameter[1]: Vstr memory reference
Type[1]: struct Vstr_ref *
Explanation:

This will call free() on the data in the Vstr_ref (Parameter[1])->ptr and then call free() on the Vstr_ref (Parameter[1]) (unless the passed reference is the NULL pointer, then it does nothing).

Function: vstr_ref_make_malloc()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Size of malloc'd area to create in the memory reference
Type[1]: size_t
Explanation:

This function will create an area of memory, using malloc, and create a Vstr memory reference to that memory. The Vstr memory reference will have a reference count of 1 and the cleanup function will point to a function to free both the reference and the copy of memory.

Function: vstr_ref_make_ptr()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Pointer to memory
Type[1]: void *
Parameter[2]: Function callback for Vstr memory reference
Type[2]: void (*)(struct Vstr_ref *)
Explanation:

This function will call malloc() to create a Vstr memory reference. The Vstr memory reference will have a reference count of 1, a pointer value of pointer passed (Parameter[1]) and a cleanup function of the function passed (Parameter[2]).

Function: vstr_ref_make_memdup()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Pointer to memory
Type[1]: void *
Parameter[2]: Length of memory block
Type[2]: size_t
Explanation:

This function will create a Vstr memory reference. The Vstr memory reference will have a reference count of 1 and a copy of the memory pointed to by (Parameter[1]) of length (Parameter[2]) will be the pointer value. The cleanup function will point to a function to free both the reference and the copy of memory.

Function: vstr_ref_make_strdup()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Pointer to data
Type[1]: char *
Explanation:

This function calls vstr_ref_make_memdup() with the length being the value of (strlen() + 1) on the data parameter (Parameter[1]).

Function: VSTR_REF_MAKE_STRDUP()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Pointer to data
Type[1]: char *
Explanation:

This macro function calls vstr_ref_make_memdup() with the length being the value of (strlen() + 1) on the data parameter (Parameter[1]).

Function: vstr_ref_make_vstr_base()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Explanation:

This function will create a Vstr memory reference. The Vstr memory reference will have a reference count of 1, a pointer value of the Vstr string (Parameter[1]). The cleanup function will point to a function to free both the reference and the Vstr string.

Function: vstr_ref_make_vstr_conf()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Explanation:

This function will create a Vstr memory reference. The Vstr memory reference will have a reference count of 1, a pointer value of the Vstr configuration (Parameter[1]). The cleanup function will point to a function to free both the reference and the Vstr configuration.

Function: vstr_ref_make_vstr_sects()
Returns: Vstr memory reference
Type: struct Vstr_ref *
Parameter[1]: Vstr sections
Type[1]: struct Vstr_sects *
Explanation:

This function will create a Vstr memory reference. The Vstr memory reference will have a reference count of 1, a pointer value of the Vstr sections (Parameter[1]). The cleanup function will point to a function to free both the reference and the Vstr sections.

Creation/destruction of core objects

Function: vstr_make_conf()
Returns: Vstr configuration
Type: struct Vstr_conf *
Parameter[1]: Nothing
Type[1]: void
Explanation:

This function will make a Vstr configuration, or return NULL.

Function: vstr_free_conf()
Returns: Nothing
Type: void
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Explanation:

This function will free a Vstr configuration, allocated by vstr_make_conf().

Function: vstr_make_base()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Explanation:

This function will make a Vstr string, or return NULL.

Note:

If the configuration (Parameter[1]) is NULL, then the global configuration is used.

If there are spare base objects, then no allocations are done.

Function: vstr_free_base()
Returns: Nothing
Type: void
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Explanation:

This function will free a Vstr string, allocated by vstr_make_base().

Note:

If the base object VSTR_CNTL_BASE_GET_TYPE_GRPALLOC_CACHE is of the same type as it's configurations VSTR_CNTL_CONF_GET_TYPE_GRPALLOC_CACHE, then the base object will be turned into a spare object so it can be reused by vstr_make_base().

Function: vstr_dup_buf()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const void *
Parameter[3]: Length of data (Parameter[2])
Type[3]: size_t
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_buf().

Function: vstr_dup_ptr()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const void *
Parameter[3]: Length of data (Parameter[2])
Type[3]: size_t
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_ptr().

Function: vstr_dup_non()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Length of non data
Type[2]: size_t
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_non().

Function: vstr_dup_ref()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Vstr memory reference
Type[2]: struct Vstr_ref *
Parameter[3]: Offset of Vstr memory reference (Parameter[2])
Type[3]: size_t
Parameter[4]: Length of Vstr memory reference (Parameter[2])
Type[4]: size_t
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_ref().

Function: vstr_dup_vstr()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Vstr string
Type[2]: const struct Vstr_base *
Parameter[3]: Start position in the Vstr string (Parameter[2])
Type[3]: size_t
Parameter[4]: Length in the Vstr string (Parameter[2])
Type[4]: size_t
Parameter[6]: Flags for Vstr add (VSTR_TYPE_ADD_*)
Type[6]: unsigned int
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_vstr().

Function: vstr_dup_rep_chr()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Character to repeat
Type[2]: char
Parameter[3]: Number of times to repeat character (Parameter[2])
Type[3]: size_t
Explanation:

This function is equivalent to calling vstr_make_base() and then vstr_add_rep_chr().

Function: vstr_dup_cstr_buf()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const char *
Explanation:

This function calls vstr_dup_buf() with the length being the value of strlen() on the data parameter (Parameter[2]).

Function: vstr_dup_cstr_ptr()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const char *
Explanation:

This function calls vstr_dup_ptr() with the length being the value of strlen() on the data parameter (Parameter[2]).

Function: vstr_dup_cstr_ref()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Vstr memory reference
Type[2]: struct Vstr_ref *
Parameter[3]: Offset of Vstr memory reference (Parameter[3])
Type[3]: size_t
Explanation:

This function calls vstr_dup_ref() with the length being the value of strlen() on the memory from the Vstr memory reference (Parameter[3]) starting at the offset (Parameter[4]).

Function: VSTR_DUP_CSTR_BUF()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const char *
Explanation:

This macro function calls vstr_dup_buf() with the length being the value of strlen() on the data parameter (Parameter[2]).

Function: VSTR_DUP_CSTR_PTR()
Returns: Vstr string
Type: struct Vstr_base *
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Pointer to data
Type[2]: const char *
Explanation:

This macro function calls vstr_dup_ptr() with the length being the value of strlen() on the data parameter (Parameter[2]).

Function: VSTR_DUP_CSTR_REF()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Vstr memory reference
Type[2]: struct Vstr_ref *
Parameter[3]: Offset of Vstr memory reference (Parameter[3])
Type[3]: size_t
Explanation:

This macro function calls vstr_dup_ref() with the length being the value of strlen() on the memory from the Vstr memory reference (Parameter[3]) starting at the offset (Parameter[4]).

Function: vstr_make_spare_nodes()
Returns: Number of nodes created
Type: unsigned int
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Type of nodes to create
Type[2]: unsigned int
Parameter[3]: Number of nodes to create
Type[3]: unsigned int
Explanation:

This function will try and create a number (Parameter[3]) of nodes of type (Parameter[2]).

Note:

The number of nodes created will be less than or equal to the number requested (Parameter[3]), however if it is less than then the malloc_bad flag will be set (Parameter[1])->malloc_bad.

If the configuration (Parameter[1]) is NULL, then the global configuration is used.

Function: vstr_free_spare_nodes()
Returns: Number of nodes destroyed
Type: unsigned int
Parameter[1]: Vstr configuration
Type[1]: struct Vstr_conf *
Parameter[2]: Type of nodes to destroy
Type[2]: unsigned int
Parameter[3]: Number of nodes to destroy
Type[3]: unsigned int
Explanation:

This function will try and destroy a number (Parameter[3]) of nodes of type (Parameter[2]).

Note:

The number of nodes destroyed will be less than or equal to the number requested (Parameter[3]), the only reason that less will be destroyed is if there are no more unused nodes of that type (Parameter[2]).

If the configuration (Parameter[1]) is NULL, then the global configuration is used.

Adding and deleting of data functions

Function: vstr_add_buf()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const void *
Parameter[4]: Length of data (Parameter[3])
Type[4]: size_t
Explanation:

This function is used to add a copy of the data in the data array to a Vstr string.

Think of this function as doing a write() into a Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Function: vstr_add_ptr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const void *
Parameter[4]: Length of data (Parameter[3])
Type[4]: size_t
Explanation:

This function is used to add a pointer to a data array to a Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

If the data in the array needs to be free'd the programer will have to decide when it is no longer being used by the Vstr string and free it. It is often easier to create a memory reference and use vstr_add_ref() instead.

Function: vstr_add_non()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length of non data
Type[3]: size_t
Explanation:

This function is used to add "non" (or invisible) data to a Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Function: vstr_add_ref()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Vstr memory reference
Type[3]: struct Vstr_ref *
Parameter[4]: Offset of Vstr memory reference (Parameter[3])
Type[4]: size_t
Parameter[5]: Length of Vstr memory reference (Parameter[3])
Type[5]: size_t
Explanation:

This function is used to add a memory reference to a Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Function: vstr_add_vstr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Vstr string
Type[3]: const struct Vstr_base *
Parameter[4]: Start position in the Vstr string (Parameter[3])
Type[4]: size_t
Parameter[5]: Length in the Vstr string (Parameter[3])
Type[5]: size_t
Parameter[6]: Type for Vstr add (VSTR_TYPE_ADD_*)
Type[6]: unsigned int
Explanation:

This function is used to add data in one Vstr string (Parameter[3]) to another Vstr string (Parameter[1]).

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The function can change how the data is added to the Vstr string (Parameter[1]) and in some cases even how the data is represented in the Vstr string (Parameter[3]) for more information see the documentation on the VSTR_TYPE_ADD_* constants.

This function will set _both_ (Parameter[1])->conf->malloc_bad and (Parameter[3])->conf->malloc_bad if any of the allocation calls fails.

Function: vstr_add_rep_chr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Character to repeat
Type[3]: char
Parameter[4]: Number of times to repeat character (Parameter[3])
Type[4]: size_t
Explanation:

This function is used to add 1 or more copies of the character (Parameter[3]) to the Vstr string.

Think of this function as doing a memset() into data in the Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Function: vstr_add_cstr_buf()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const char *
Explanation:

This function calls vstr_add_buf() with the length being the value of strlen() on the data parameter (Parameter[3]).

Function: vstr_add_cstr_ptr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const char *
Explanation:

This function calls vstr_add_ptr() with the length being the value of strlen() on the data parameter (Parameter[3]).

Function: vstr_add_cstr_ref()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Vstr memory reference
Type[3]: struct Vstr_ref *
Parameter[4]: Offset of Vstr memory reference (Parameter[3])
Type[4]: size_t
Explanation:

This function calls vstr_add_ref() with the length being the value of strlen() on the memory from the Vstr memory reference (Parameter[3]) starting at the offset (Parameter[4]).

Function: VSTR_ADD_CSTR_BUF()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const char *
Explanation:

This macro function calls vstr_add_buf() with the length being the value of strlen() on the data parameter (Parameter[3]).

Function: VSTR_ADD_CSTR_PTR()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Pointer to data
Type[3]: const char *
Explanation:

This macro function calls vstr_add_ptr() with the length being the value of strlen() on the data parameter (Parameter[3]).

Function: VSTR_ADD_CSTR_REF()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Vstr memory reference
Type[3]: struct Vstr_ref *
Parameter[4]: Offset of Vstr memory reference (Parameter[3])
Type[4]: size_t
Explanation:

This macro function calls vstr_add_ref() with the length being the value of strlen() on the memory from the Vstr memory reference (Parameter[3]) starting at the offset (Parameter[4]).

Function: vstr_add_vfmt()
Returns: Number of bytes added
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Format string, a superset of the rules for C99 printf
Type[3]: const char *
Parameter[4]: Standard argument object from va_start()
Type[4]: va_list
Explanation:

This function works like calling vsprintf() directly into a Vstr string, however this is a portable implementation which is feature complete with glibc-2.2.x sprintf(); implements custom specifiers, if you use the vstr_fmt_add() function, and doesn't require a double copy.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

Depending on how the library was compiled double support is implemented by either calling the underlying host implementation of sprintf(), by internal code or simply by assuming all double's are zero. When using the host implementation system bugs of inaccuracy will show through, however the feature set remains the same (Ie. the ' flag works the same).

Because specifiers can be overridden using vstr_fmt_add() if you are adding data to a Vstr string that you didn't create you should use either vstr_add_vsysfmt() or vstr_swap_conf().

Function: vstr_add_fmt()
Returns: Number of bytes added
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Format string, a superset of the rules for C99 printf
Type[3]: const char *
Parameter[4]: Options depending on value of Parameter[3]
Type[4]: ...
Explanation:

This just calls vstr_add_vfmt() after converting the argument list (Parameter[4]) a va_list object.

Function: vstr_add_vsysfmt()
Returns: Number of bytes added
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Format string, a superset of the rules for C99 printf
Type[3]: const char *
Parameter[4]: Standard argument object from va_start()
Type[4]: va_list
Explanation:

This function does the same thing as vstr_add_vfmt() but ignores custom specifiers (see vstr_fmt_add()).

Function: vstr_add_sysfmt()
Returns: Number of bytes added
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Format string, a superset of the rules for C99 printf
Type[3]: const char *
Parameter[4]: Options depending on value of Parameter[3]
Type[4]: ...
Explanation:

This just calls vstr_add_vsysfmt() after converting the argument list (Parameter[4]) a va_list object.

Function: vstr_add_iovec_buf_beg()
Returns: Number of bytes in the iovec array
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Minimum amount of iovecs to add
Type[3]: unsigned int
Parameter[4]: Maximum amount of iovecs to add
Type[4]: unsigned int
Parameter[5]: Returns the start of the iovec array
Type[5]: struct iovec **
Parameter[6]: Returns the number of iovec structures in the array
Type[6]: unsigned int *
Explanation:

This function is used to add a copy of data directly into the Vstr string, the amount of data available will be between the minimum (Parameter[4]) and maximum ((Parameter[5]) + 1) number of iovecs multiplied by the length of data in _BUF type nodes. The obvious use for the data is to call readv() on it.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

You shouldn't call any other vstr functions between vstr_add_iovec_buf_beg() and vstr_add_iovec_buf_end(), unless you know that they are operating on a different Vstr string which is using a different Vstr configuration.

The reason there is a +1 on the maximum value is that data may be appended to a _BUF node just before the start of where the data is to go, this is almost guaranteed to happen when adding to the end of a Vstr string and saves a lot of wasted space.

It is currently believed that, on Linux, doing disk IO in amounts greater than 8k gives little real performance improvement. This can be converted into iovec numbers by using a formula like...

    min = (8k / buf_sz) + 2;
    max = min + (min / 2);    

...where the +2 is due to both the extra space at the end of the current last node, and rounding errors due to the division. The max being slightly bigger is an attempt to make the constant overhead of the call slightly less, and may not be useful. It is very possible that some kind of dynamic scaling of the values would result in the best performance, however the solution to that doesn't fit in the margin :).

Function: vstr_add_iovec_buf_end()
Returns: Nothing
Type: void
Parameter[1]: Vstr string
Type[1]: const struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Number of bytes added to the iovec array
Type[3]: size_t
Explanation:

This function is used after calling vstr_add_iovec_buf_beg() and you've then filled in a bunch of data.

Note:

Although it's safe to not bother calling this function if you didn't have anything to add to the Vstr string it is often more efficient to call this function with Parameter[3] as 0.

Function: vstr_add_netstr_beg()
Returns: Position of start of netstr (Parameter[2]) + 1
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Explanation:

This function creates the start of a netstring http://cr.yp.to/proto/netstrings.txt this can be used in conjunction with vstr_add_netstr_end() to easily create netstrings.

Function: vstr_add_netstr_end()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Position returned from vstr_add_netstr_beg()
Type[2]: size_t
Parameter[3]: End of netstring
Type[3]: size_t
Explanation:

This function is called after calling vstr_add_netstr_beg(), adding all the data you want to the netstring and then passing the position of the end of that data.

Upon success a valid netstring will contain all the data added between the two calls.

Note:

It is valid to pass the same values for (Parameter[2]) and (parameter[3]), as that signifies that there is no data in the netstring.

It is almost guaranteed that data will need to be removed from the beginning of the netstring due to the length being shorter than the maximum, this is inefficient and could cause problems if you know how big the Vstr string is you can use the vstr_add_netstr2_* functions to solve both problems.

Function: vstr_add_netstr2_beg()
Returns: Position of start of netstr (Parameter[2]) + 1
Type: size_t
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Explanation:

This function creates the start of a netstring2 which is like a netstring http://cr.yp.to/proto/netstrings.txt but can have leading zeros, this can be used in conjunction with vstr_add_netstr2_end() to easily create netstring2s.

Function: vstr_add_netstr2_end()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Position returned from vstr_add_netstr2_beg()
Type[2]: size_t
Parameter[3]: End of netstring2
Type[3]: size_t
Explanation:

This function is called after calling vstr_add_netstr2_beg(), adding all the data you want to the netstring2 and then passing the position of the end of that data.

Upon success a netstring2 will contain all the data added between the two calls.

Note:

It is valid to pass the same values for (Parameter[2]) and (parameter[3]), as that signifies that there is no data in the netstring.

No data is ever removed from the beginning of a netstring2, this is incompatible with the netstring spec. but is more efficient and doesn't cause problems if you know how big the Vstr string is and can't have it lose data from the beginning/middle.

Function: vstr_del()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Explanation:

This function is used to delete data in the Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

Deleted nodes do not get returned to the system, they get put into a pool in the Vstr configuration for reuse on the next call to a vstr_add_*() function.

Deleting the entire Vstr string and deleting from the beginning onward are faster operations than a generic delete. They also never require allocating memory and so the return value can be ignored.

Function: vstr_mov()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Append position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Vstr string
Type[3]: struct Vstr_base *
Parameter[4]: Start position in the Vstr string (Parameter[3])
Type[4]: size_t
Parameter[5]: Length in the Vstr string (Parameter[3])
Type[5]: size_t
Explanation:

This function is used to move data, deleting it from one Vstr string (Parameter[3]) and adding it to another Vstr string (Parameter[1]).

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Substitution of data functions

Function: vstr_sub_buf()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Pointer to data
Type[4]: const void *
Parameter[5]: Length of data (Parameter[4])
Type[5]: size_t
Explanation:

This function is used to substitute the data in the Vstr string with a copy of the data in the data array.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[5]).

Think of this function as doing a vstr_del() and then a vstr_add_buf() (but it's atomic).

If the length of the data (Parameter[5]) is less than or equal to the length of the Vstr string (Parameter[3]) and the data in the Vstr string is in a BUF node then the data will just be overwritten (Ie. no allocations will happen).

Function: vstr_sub_ptr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Pointer to data
Type[4]: const void *
Parameter[5]: Length of data (Parameter[4])
Type[5]: size_t
Explanation:

This function is used to substitute the data in the Vstr string with a pointer to a data array.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[7]), think of this function like doing a vstr_del() and then a vstr_add_ptr() (but it's atomic).

Function: vstr_sub_non()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Length of non data
Type[4]: size_t
Explanation:

This function is used to substitute the data in the Vstr string with "non" (or invisible) data.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[7]), think of this function like doing a vstr_del() and then a vstr_add_non() (but it's atomic).

Function: vstr_sub_ref()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Vstr memory reference
Type[4]: struct Vstr_ref *
Parameter[5]: Offset of Vstr memory reference (Parameter[4])
Type[5]: size_t
Parameter[6]: Length of Vstr memory reference (Parameter[4])
Type[6]: size_t
Explanation:

This function is used to substitute the data in the Vstr string with a memory reference.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[7]), think of this function like doing a vstr_del() and then a vstr_add_ref() (but it's atomic).

Function: vstr_sub_vstr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Vstr string
Type[4]: const struct Vstr_base *
Parameter[5]: Start position in the Vstr string (Parameter[4])
Type[5]: size_t
Parameter[6]: Length in the Vstr string (Parameter[4])
Type[6]: size_t
Parameter[6]: Type for Vstr sub (VSTR_TYPE_SUB_*)
Type[6]: unsigned int
Explanation:

This function is used to substitute the data in the Vstr string (Parameter[1]) with the data in another Vstr string (Parameter[4]).

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[7]), think of this function like doing a vstr_del() and then a vstr_add_vstr() (but it's atomic).

The function can change how the data is added to the Vstr string (Parameter[1]) and in some cases even how the data is represented in the Vstr string (Parameter[3]) for more information see the documentation on the VSTR_TYPE_SUB_* constants.

Function: vstr_sub_rep_chr()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the Vstr string (Parameter[1])
Type[2]: size_t
Parameter[3]: Length in the Vstr string (Parameter[1])
Type[3]: size_t
Parameter[4]: Character to repeat
Type[4]: char
Parameter[5]: Number of times to repeat character (Parameter[3])
Type[5]: size_t
Explanation:

This function is used to substitute the data in the Vstr string with one or more copies of the character (Parameter[3]).

Think of this function as doing a memset() into data in the Vstr string.

If the function can detect that the values of parameters are in error the function will return 0 to indicate an error.

The function will return 0 if it needs to allocate memory and cannot do so, although if it does fail the Vstr string won't have changed (Ie. the function is atomic).

Note:

The length of the Vstr string (Parameter[3]) can be larger or smaller than the length of the data (Parameter[5]).

Think of this function as doing a vstr_del() and then a vstr_add_rep_chr() (but it's atomic).

If the length of the data (Parameter[5]) is equal to the length of the Vstr string (Parameter[3]) and the data in the Vstr string is in a BUF node then the data will just be overwritten (Ie. no allocations will happen).

Function: vstr_sub_cstr_buf()
Returns: TRUE on success and FALSE on failure
Type: int
Parameter[1]: Vstr string
Type[1]: struct Vstr_base *
Parameter[2]: Start position in the