#include <libetpan/libetpan.h> struct _MMAPString { char * str; size_t len; size_t allocated_len; int fd; size_t mmapped_size; }; typedef struct _MMAPString MMAPString;
MMAPString is a string which size that can increase automatically.
MMAPString * mmap_string_new(const char * init); MMAPString * mmap_string_new_len(const char * init, size_t len); MMAPString * mmap_string_sized_new(size_t dfl_size); void mmap_string_free(MMAPString * string);
mmap_string_new() allocates a new string. init is the intial value of the string. NULL will be returned on error.
mmap_string_new_len() allocates a new string. init is the intial value of the string, len is the length of the initial string. NULL will be returned on error.
mmap_string_sized_new() allocates a new string. dfl_size is the initial allocation of the string. NULL will be returned on error.
mmap_string_free() release the memory used by the string.
MMAPString * mmap_string_assign(MMAPString * string, const char * rval); MMAPString * mmap_string_truncate(MMAPString *string, size_t len);
mmap_string_assign() sets a new value for the given string. NULL will be returned on error.
mmap_string_truncate() sets a length for the string. NULL will be returned on error.
MMAPString * mmap_string_set_size (MMAPString * string, size_t len);
sets the allocation of the string. NULL will be returned on error.
MMAPString * mmap_string_insert_len(MMAPString * string, size_t pos, const char * val, size_t len); MMAPString * mmap_string_append(MMAPString * string, const char * val); MMAPString * mmap_string_append_len(MMAPString * string, const char * val, size_t len); MMAPString * mmap_string_append_c(MMAPString * string, char c); MMAPString * mmap_string_prepend(MMAPString * string, const char * val); MMAPString * mmap_string_prepend_c(MMAPString * string, char c); MMAPString * mmap_string_prepend_len(MMAPString * string, const char * val, size_t len); MMAPString * mmap_string_insert(MMAPString * string, size_t pos, const char * val); MMAPString * mmap_string_insert_c(MMAPString *string, size_t pos, char c); MMAPString * mmap_string_erase(MMAPString * string, size_t pos, size_t len);
For complexity here, n is the size of the given MMAPString, and len is the size of the string to insert.
mmap_string_insert_len() inserts the given string value of given length in the string at the given position. NULL will be returned on error. Complexity is O(n + len).
mmap_string_append() appends the given string value at the end of the string. NULL will be returned on error. Complexity is O(len).
mmap_string_append_len() appends the given string value of given length at the end of the string. NULL will be returned on error. Complexity is O(len).
mmap_string_append_c() appends the given character at the end of the string. NULL will be returned on error. Complexity is O(1).
mmap_string_prepend() insert the given string value at the beginning of the string. NULL will be returned on error. Complexity is O(n + len).
mmap_string_prepend_c() insert the given character at the beginning of the string. NULL will be returned on error. Complexity is O(n).
mmap_string_prepend_len() insert the given string value of given length at the beginning of the string. NULL will be returned on error. Complexity is O(n + len).
mmap_string_insert() inserts the given string value in the string at the given position. NULL will be returned on error. Complexity is O(n + len).
mmap_string_insert_c() inserts the given character in the string at the given position. NULL will be returned on error. Complexity is O(n).
mmap_string_erase() removes the given count of characters (len) at the given position of the string. NULL will be returned on error. Complexity is O(n).
int mmap_string_ref(MMAPString * string); int mmap_string_unref(char * str);
MMAPString provides a mechanism that let you use MMAPString like normal strings. You have first to use mmap_string_ref(), so that you notify that the string will be used as a normal string, then, you use mmapstr->str to refer to the string. When you have finished and you want to free a string corresponding to a MMAPString, you will use mmap_string_unref.
mmap_string_ref() references the string so that the array of characters can be used as a normal string then released with mmap_string_unref(). The array of characters will be obtained with string->str. returns -1 on error, 0 on success.