tcutil

Langue: en

Version: 270233 (debian - 07/07/09)

Section: 3 (Bibliothèques de fonctions)

NAME

tcutil - the utility API

DESCRIPTION

The utility API is a set of routines to handle records on memory easily. Especially, extensible string, array list, and hash map are useful.

To use the utility API, include `tcutil.h' and related standard header files. Usually, write the following description near the front of a source file.


#include <tcutil.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <stdint.h>

Objects whose type is pointer to `TCXSTR' are used for extensible string. An extensible string object is created with the function `tcxstrnew' and is deleted with the function `tcxstrdel'. Objects whose type is pointer to `TCLIST' are used for array list. A list object is created with the function `tclistnew' and is deleted with the function `tclistdel'. Objects whose type is pointer to `TCMAP' are used for hash map. A map object is created with the function `tcmapnew' and is deleted with the function `tcmapdel'. To avoid memory leak, it is important to delete every object when it is no longer in use.

API OF BASIC UTILITIES

The constant `tcversion' is the string containing the version information.


extern const char *tcversion;

The variable `tcfatalfunc' is the pointer to the call back function for handling a fatal error.


extern void (*tcfatalfunc)(const char *);
The argument specifies the error message.
The initial value of this variable is `NULL'. If the value is `NULL', the default function is called when a fatal error occurs. A fatal error occurs when memory allocation is failed.

The function `tcmalloc' is used in order to allocate a region on memory.


void *tcmalloc(size_t size);
`size' specifies the size of the region.
The return value is the pointer to the allocated region.
This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tccalloc' is used in order to allocate a nullified region on memory.


void *tccalloc(size_t nmemb, size_t size);
`nmemb' specifies the number of elements.
`size' specifies the size of each element.
The return value is the pointer to the allocated nullified region.
This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `calloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcrealloc' is used in order to re-allocate a region on memory.


void *tcrealloc(void *ptr, size_t size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the pointer to the re-allocated region.
This function handles failure of memory allocation implicitly. Because the region of the return value is allocated with the `realloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmemdup' is used in order to duplicate a region on memory.


void *tcmemdup(const void *ptr, size_t size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the pointer to the allocated region of the duplicate.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcstrdup' is used in order to duplicate a string on memory.


char *tcstrdup(const void *str);
`str' specifies the string.
The return value is the allocated string equivalent to the specified string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcfree' is used in order to free a region on memory.


void tcfree(void *ptr);
`ptr' specifies the pointer to the region. If it is `NULL', this function has no effect.
Although this function is just a wrapper of `free' call, this is useful in applications using another package of the `malloc' series.

API OF EXTENSIBLE STRING

The function `tcxstrnew' is used in order to create an extensible string object.


TCXSTR *tcxstrnew(void);
The return value is the new extensible string object.

The function `tcxstrnew2' is used in order to create an extensible string object from a character string.


TCXSTR *tcxstrnew2(const char *str);
`str' specifies the string of the initial content.
The return value is the new extensible string object containing the specified string.

The function `tcxstrnew3' is used in order to create an extensible string object with the initial allocation size.


TCXSTR *tcxstrnew3(int asiz);
`asiz' specifies the initial allocation size.
The return value is the new extensible string object.

The function `tcxstrdup' is used in order to copy an extensible string object.


TCXSTR *tcxstrdup(const TCXSTR *xstr);
`xstr' specifies the extensible string object.
The return value is the new extensible string object equivalent to the specified object.

The function `tcxstrdel' is used in order to delete an extensible string object.


void tcxstrdel(TCXSTR *xstr);
`xstr' specifies the extensible string object.
Note that the deleted object and its derivatives can not be used anymore.

The function `tcxstrcat' is used in order to concatenate a region to the end of an extensible string object.


void tcxstrcat(TCXSTR *xstr, const void *ptr, int size);
`xstr' specifies the extensible string object.
`ptr' specifies the pointer to the region to be appended.
`size' specifies the size of the region.

The function `tcxstrcat2' is used in order to concatenate a character string to the end of an extensible string object.


void tcxstrcat2(TCXSTR *xstr, const char *str);
`xstr' specifies the extensible string object.
`str' specifies the string to be appended.

The function `tcxstrptr' is used in order to get the pointer of the region of an extensible string object.


const void *tcxstrptr(const TCXSTR *xstr);
`xstr' specifies the extensible string object.
The return value is the pointer of the region of the object.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.

The function `tcxstrsize' is used in order to get the size of the region of an extensible string object.


int tcxstrsize(const TCXSTR *xstr);
`xstr' specifies the extensible string object.
The return value is the size of the region of the object.

The function `tcxstrclear' is used in order to clear an extensible string object.


void tcxstrclear(TCXSTR *xstr);
`xstr' specifies the extensible string object.
The internal buffer of the object is cleared and the size is set zero.

The function `tcxstrtomalloc' is used in order to convert an extensible string object into a usual allocated region.


void *tcxstrtomalloc(TCXSTR *xstr);
`xstr' specifies the extensible string object.
The return value is the pointer to the allocated region of the object.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. Because the region of the original object is deleted, it should not be deleted again.

The function `tcxstrfrommalloc' is used in order to create an extensible string object from an allocated region.


TCXSTR *tcxstrfrommalloc(void *ptr, int size);
`ptr' specifies the pointer to the region allocated with `malloc' call.
`size' specifies the size of the region.
The return value is the new extensible string object wrapping the specified region.
Note that the specified region is released when the object is deleted.

The function `tcxstrprintf' is used in order to perform formatted output into an extensible string object.


void tcxstrprintf(TCXSTR *xstr, const char *format, ...);
`xstr' specifies the extensible string object.
`format' specifies the printf-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. The other conversion character work as with each original.
The other arguments are used according to the format string.

The function `tcsprintf' is used in order to allocate a formatted string on memory.


char *tcsprintf(const char *format, ...);
`format' specifies the printf-like format string. The conversion character `%' can be used with such flag characters as `s', `d', `o', `u', `x', `X', `c', `e', `E', `f', `g', `G', `@', `?', `%'. `@' works as with `s' but escapes meta characters of XML. `?' works as with `s' but escapes meta characters of URL. The other conversion character work as with each original.
The other arguments are used according to the format string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

API OF ARRAY LIST

The function `tclistnew' is used in order to create a list object.


TCLIST *tclistnew(void);
The return value is the new list object.

The function `tclistnew2' is used in order to create a list object with expecting the number of elements.


TCLIST *tclistnew2(int anum);
`anum' specifies the number of elements expected to be stored in the list.
The return value is the new list object.

The function `tclistdup' is used in order to copy a list object.


TCLIST *tclistdup(const TCLIST *list);
`list' specifies the list object.
The return value is the new list object equivalent to the specified object.

The function `tclistdel' is used in order to delete a list object.


void tclistdel(TCLIST *list);
`list' specifies the list object.
Note that the deleted object and its derivatives can not be used anymore.

The function `tclistnum' is used in order to get the number of elements of a list object.


int tclistnum(const TCLIST *list);
`list' specifies the list object.
The return value is the number of elements of the list.

The function `tclistval' is used in order to get the pointer to the region of an element of a list object.


const void *tclistval(const TCLIST *list, int index, int *sp);
`list' specifies the list object.
`index' specifies the index of the element.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the value.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. If `index' is equal to or more than the number of elements, the return value is `NULL'.

The function `tclistval2' is used in order to get the string of an element of a list object.


const char *tclistval2(const TCLIST *list, int index);
`list' specifies the list object.
`index' specifies the index of the element.
The return value is the string of the value.
If `index' is equal to or more than the number of elements, the return value is `NULL'.

The function `tclistpush' is used in order to add an element at the end of a list object.


void tclistpush(TCLIST *list, const void *ptr, int size);
`list' specifies the list object.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region.

The function `tclistpush2' is used in order to add a string element at the end of a list object.


void tclistpush2(TCLIST *list, const char *str);
`list' specifies the list object.
`str' specifies the string of the new element.

The function `tclistpushmalloc' is used in order to add an allocated element at the end of a list object.


void tclistpushmalloc(TCLIST *list, void *ptr, int size);
`list' specifies the list object.
`ptr' specifies the pointer to the region allocated with `malloc' call.
`size' specifies the size of the region.
Note that the specified region is released when the object is deleted.

The function `tclistpop' is used in order to remove an element of the end of a list object.


void *tclistpop(TCLIST *list, int *sp);
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If the list is empty, the return value is `NULL'.

The function `tclistpop2' is used in order to remove a string element of the end of a list object.


char *tclistpop2(TCLIST *list);
`list' specifies the list object.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If the list is empty, the return value is `NULL'.

The function `tclistunshift' is used in order to add an element at the top of a list object.


void tclistunshift(TCLIST *list, const void *ptr, int size);
`list' specifies the list object.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region.

The function `tclistunshift2' is used in order to add a string element at the top of a list object.


void tclistunshift2(TCLIST *list, const char *str);
`list' specifies the list object.
`str' specifies the string of the new element.

The function `tclistshift' is used in order to remove an element of the top of a list object.


void *tclistshift(TCLIST *list, int *sp);
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If the list is empty, the return value is `NULL'.

The function `tclistshift2' is used in order to remove a string element of the top of a list object.


char *tclistshift2(TCLIST *list);
`list' specifies the list object.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If the list is empty, the return value is `NULL'.

The function `tclistinsert' is used in order to add an element at the specified location of a list object.


void tclistinsert(TCLIST *list, int index, const void *ptr, int size);
`list' specifies the list object.
`index' specifies the index of the new element.
`ptr' specifies the pointer to the region of the new element.
`size' specifies the size of the region.
If `index' is equal to or more than the number of elements, this function has no effect.

The function `tclistinsert2' is used in order to add a string element at the specified location of a list object.


void tclistinsert2(TCLIST *list, int index, const char *str);
`list' specifies the list object.
`index' specifies the index of the new element.
`str' specifies the string of the new element.
If `index' is equal to or more than the number of elements, this function has no effect.

The function `tclistremove' is used in order to remove an element at the specified location of a list object.


void *tclistremove(TCLIST *list, int index, int *sp);
`list' specifies the list object.
`index' specifies the index of the element to be removed.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the removed element.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If `index' is equal to or more than the number of elements, no element is removed and the return value is `NULL'.

The function `tclistremove2' is used in order to remove a string element at the specified location of a list object.


char *tclistremove2(TCLIST *list, int index);
`list' specifies the list object.
`index' specifies the index of the element to be removed.
The return value is the string of the removed element.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. If `index' is equal to or more than the number of elements, no element is removed and the return value is `NULL'.

The function `tclistover' is used in order to overwrite an element at the specified location of a list object.


void tclistover(TCLIST *list, int index, const void *ptr, int size);
`list' specifies the list object.
`index' specifies the index of the element to be overwritten.
`ptr' specifies the pointer to the region of the new content.
`size' specifies the size of the new content.
If `index' is equal to or more than the number of elements, this function has no effect.

The function `tclistover2' is used in order to overwrite a string element at the specified location of a list object.


void tclistover2(TCLIST *list, int index, const char *str);
`list' specifies the list object.
`index' specifies the index of the element to be overwritten.
`str' specifies the string of the new content.
If `index' is equal to or more than the number of elements, this function has no effect.

The function `tclistsort' is used in order to sort elements of a list object in lexical order.


void tclistsort(TCLIST *list);
`list' specifies the list object.

The function `tclistsortci' is used in order to sort elements of a list object in case-insensitive lexical order.


void tclistsortci(TCLIST *list);
`list' specifies the list object.

The function `tclistsortex' is used in order to sort elements of a list object by an arbitrary comparison function.


void tclistsortex(TCLIST *list, int (*cmp)(const TCLISTDATUM *, const TCLISTDATUM *));
`list' specifies the list object.
`cmp' specifies the pointer to the comparison function. The structure `TCLISTDATUM' has the member "ptr" which is the pointer to the region of the element, and the member "size" which is the size of the region.

The function `tclistlsearch' is used in order to search a list object for an element using liner search.


int tclistlsearch(const TCLIST *list, const void *ptr, int size);
`list' specifies the list object.
`ptr' specifies the pointer to the region of the key.
`size' specifies the size of the region.
The return value is the index of a corresponding element or -1 if there is no corresponding element.
If two or more elements correspond, the former returns.

The function `tclistbsearch' is used in order to search a list object for an element using binary search.


int tclistbsearch(const TCLIST *list, const void *ptr, int size);
`list' specifies the list object. It should be sorted in lexical order.
`ptr' specifies the pointer to the region of the key.
`size' specifies the size of the region.
The return value is the index of a corresponding element or -1 if there is no corresponding element.
If two or more elements correspond, which returns is not defined.

The function `tclistclear' is used in order to clear a list object.


void tclistclear(TCLIST *list);
`list' specifies the list object.
All elements are removed.

The function `tclistdump' is used in order to serialize a list object into a byte array.


void *tclistdump(const TCLIST *list, int *sp);
`list' specifies the list object.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result serial region.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tclistload' is used in order to create a list object from a serialized byte array.


TCLIST *tclistload(const void *ptr, int size);
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
The return value is a new list object.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

API OF HASH MAP

The function `tcmapnew' is used in order to create a map object.


TCMAP *tcmapnew(void);
The return value is the new map object.

The function `tcmapnew2' is used in order to create a map object with specifying the number of the buckets.


TCMAP *tcmapnew2(uint32_t bnum);
`bnum' specifies the number of the buckets.
The return value is the new map object.

The function `tcmapdup' is used in order to copy a map object.


TCMAP *tcmapdup(const TCMAP *map);
`map' specifies the map object.
The return value is the new map object equivalent to the specified object.

The function `tcmapdel' is used in order to delete a map object.


void tcmapdel(TCMAP *map);
`map' specifies the map object.
Note that the deleted object and its derivatives can not be used anymore.

The function `tcmapput' is used in order to store a record into a map object.


void tcmapput(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the map, it is overwritten.

The function `tcmapput2' is used in order to store a string record into a map object.


void tcmapput2(TCMAP *map, const char *kstr, const char *vstr);
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the map, it is overwritten.

The function `tcmapput3' is used in order to store a record of the value of two regions into a map object.


void tcmapput3(TCMAP *map, const char *kbuf, int ksiz, const void *fvbuf, int fvsiz, const char *lvbuf, int lvsiz);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`fvbuf' specifies the pointer to the former region of the value.
`fvsiz' specifies the size of the former region of the value.
`lvbuf' specifies the pointer to the latter region of the value.
`lvsiz' specifies the size of the latter region of the value.
If a record with the same key exists in the map, it is overwritten.

The function `tcmapputkeep' is used in order to store a new record into a map object.


bool tcmapputkeep(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the map, this function has no effect.

The function `tcmapputkeep2' is used in order to store a new string record into a map object.


bool tcmapputkeep2(TCMAP *map, const char *kstr, const char *vstr);
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the map, this function has no effect.

The function `tcmapputcat' is used in order to concatenate a value at the end of the value of the existing record in a map object.


void tcmapputcat(TCMAP *map, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created.

The function `tcmapputcat2' is used in order to concatenate a string value at the end of the value of the existing record in a map object.


void tcmapputcat2(TCMAP *map, const char *kstr, const char *vstr);
`map' specifies the map object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created.

The function `tcmapout' is used in order to remove a record of a map object.


bool tcmapout(TCMAP *map, const void *kbuf, int ksiz);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmapout2' is used in order to remove a string record of a map object.


bool tcmapout2(TCMAP *map, const char *kstr);
`map' specifies the map object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmapget' is used in order to retrieve a record in a map object.


const void *tcmapget(const TCMAP *map, const void *kbuf, int ksiz, int *sp);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.

The function `tcmapget2' is used in order to retrieve a string record in a map object.


const char *tcmapget2(const TCMAP *map, const char *kstr);
`map' specifies the map object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record. `NULL' is returned when no record corresponds.

The function `tcmapget3' is used in order to retrieve a semivolatile record in a map object.


const void *tcmapget3(TCMAP *map, const void *kbuf, int ksiz, int *sp);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. The internal region of the returned record is moved to the tail so that the record will survive for a time under LRU cache algorithm removing records from the head.

The function `tcmapmove' is used in order to move a record to the edge of a map object.


bool tcmapmove(TCMAP *map, const void *kbuf, int ksiz, bool head);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of a key.
`ksiz' specifies the size of the region of the key.
`head' specifies the destination which is head if it is true or tail if else.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmapmove2' is used in order to move a string record to the edge of a map object.


bool tcmapmove2(TCMAP *map, const char *kstr, bool head);
`map' specifies the map object.
`kstr' specifies the string of a key.
`head' specifies the destination which is head if it is true or tail if else.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmapiterinit' is used in order to initialize the iterator of a map object.


void tcmapiterinit(TCMAP *map);
`map' specifies the map object.
The iterator is used in order to access the key of every record stored in the map object.

The function `tcmapiternext' is used in order to get the next key of the iterator of a map object.


const void *tcmapiternext(TCMAP *map, int *sp);
`map' specifies the map object.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. The order of iteration is assured to be the same as the stored order.

The function `tcmapiternext2' is used in order to get the next key string of the iterator of a map object.


const char *tcmapiternext2(TCMAP *map);
`map' specifies the map object.
If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator.
The order of iteration is assured to be the same as the stored order.

The function `tcmapiterval' is used in order to get the value bound to the key fetched from the iterator of a map object.


const void *tcmapiterval(const void *kbuf, int *sp);
`kbuf' specifies the pointer to the region of the iteration key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the value of the corresponding record.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.

The function `tcmapiterval2' is used in order to get the value string bound to the key fetched from the iterator of a map object.


const char *tcmapiterval2(const char *kstr);
`kstr' specifies the string of the iteration key.
The return value is the pointer to the region of the value of the corresponding record.

The function `tcmaprnum' is used in order to get the number of records stored in a map object.


uint64_t tcmaprnum(const TCMAP *map);
`map' specifies the map object.
The return value is the number of the records stored in the map object.

The function `tcmapmsiz' is used in order to get the total size of memory used in a map object.


uint64_t tcmapmsiz(const TCMAP *map);
`map' specifies the map object.
The return value is the total size of memory used in a map object.

The function `tcmapkeys' is used in order to create a list object containing all keys in a map object.


TCLIST *tcmapkeys(const TCMAP *map);
`map' specifies the map object.
The return value is the new list object containing all keys in the map object.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

The function `tcmapvals' is used in order to create a list object containing all values in a map object.


TCLIST *tcmapvals(const TCMAP *map);
`map' specifies the map object.
The return value is the new list object containing all values in the map object.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

The function `tcmapaddint' is used in order to add an integer to a record in a map object.


void tcmapaddint(TCMAP *map, const char *kbuf, int ksiz, int num);
`map' specifies the map object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`num' specifies the additional value.
If the corresponding record exists, the value is treated as a integer and is added to. If no record corresponds, a new record of the additional value is stored.

The function `tcmapclear' is used in order to clear a map object.


void tcmapclear(TCMAP *map);
`map' specifies the map object.
All records are removed.

The function `tcmapcutfront' is used in order to remove front records of a map object.


void tcmapcutfront(TCMAP *map, int num);
`map' specifies the map object.
`num' specifies the number of records to be removed.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmapdump' is used in order to serialize a map object into a byte array.


void *tcmapdump(const TCMAP *map, int *sp);
`map' specifies the map object.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result serial region.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmapload' is used in order to create a map object from a serialized byte array.


TCMAP *tcmapload(const void *ptr, int size);
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
The return value is a new map object.
Because the object of the return value is created with the function `tcmapnew', it should be deleted with the function `tcmapdel' when it is no longer in use.

The function `tcmaploadone' is used in order to extract a map record from a serialized byte array.


void *tcmaploadone(const void *ptr, int size, const void *kbuf, int ksiz, int *sp);
`ptr' specifies the pointer to the region of serialized byte array.
`size' specifies the size of the region.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string.

API OF ON-MEMORY DATABASE

The function `tcmdbnew' is used in order to create an on-memory database object.


TCMDB *tcmdbnew(void);
The return value is the new on-memory database object.
The object can be shared by plural threads because of the internal mutex.

The function `tcmdbnew2' is used in order to create an on-memory database object with specifying the number of the buckets.


TCMDB *tcmdbnew2(uint32_t bnum);
`bnum' specifies the number of the buckets.
The return value is the new on-memory database object.
The object can be shared by plural threads because of the internal mutex.

The function `tcmdbdel' is used in order to delete an on-memory database object.


void tcmdbdel(TCMDB *mdb);
`mdb' specifies the on-memory database object.

The function `tcmdbput' is used in order to store a record into an on-memory database object.


void tcmdbput(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If a record with the same key exists in the database, it is overwritten.

The function `tcmdbput2' is used in order to store a string record into an on-memory database object.


void tcmdbput2(TCMDB *mdb, const char *kstr, const char *vstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If a record with the same key exists in the database, it is overwritten.

The function `tcmdbput3' is used in order to store a record of the value of two regions into an on-memory database object.


void tcmdbput3(TCMDB *mdb, const char *kbuf, int ksiz, const void *fvbuf, int fvsiz, const char *lvbuf, int lvsiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`fvbuf' specifies the pointer to the former region of the value.
`fvsiz' specifies the size of the former region of the value.
`lvbuf' specifies the pointer to the latter region of the value.
`lvsiz' specifies the size of the latter region of the value.
If a record with the same key exists in the database, it is overwritten.

The function `tcmdbputkeep' is used in order to store a new record into an on-memory database object.


bool tcmdbputkeep(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect.

The function `tcmdbputkeep2' is used in order to store a new string record into an on-memory database object.


bool tcmdbputkeep2(TCMDB *mdb, const char *kstr, const char *vstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If successful, the return value is true, else, it is false.
If a record with the same key exists in the database, this function has no effect.

The function `tcmdbputcat' is used in order to concatenate a value at the end of the value of the existing record in an on-memory database.


void tcmdbputcat(TCMDB *mdb, const void *kbuf, int ksiz, const void *vbuf, int vsiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`vbuf' specifies the pointer to the region of the value.
`vsiz' specifies the size of the region of the value.
If there is no corresponding record, a new record is created.

The function `tcmdbputcat2' is used in order to concatenate a string at the end of the value of the existing record in an on-memory database.


void tcmdbputcat2(TCMDB *mdb, const char *kstr, const char *vstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
`vstr' specifies the string of the value.
If there is no corresponding record, a new record is created.

The function `tcmdbout' is used in order to remove a record of an on-memory database object.


bool tcmdbout(TCMDB *mdb, const void *kbuf, int ksiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmdbout2' is used in order to remove a string record of an on-memory database object.


bool tcmdbout2(TCMDB *mdb, const char *kstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

The function `tcmdbget' is used in order to retrieve a record in an on-memory database object.


void *tcmdbget(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmdbget2' is used in order to retrieve a string record in an on-memory database object.


char *tcmdbget2(TCMDB *mdb, const char *kstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
If successful, the return value is the string of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmdbget3' is used in order to retrieve a record and move it astern in an on-memory database object.


void *tcmdbget3(TCMDB *mdb, const void *kbuf, int ksiz, int *sp);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the region of the value of the corresponding record. `NULL' is returned when no record corresponds.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. The internal region of the returned record is moved to the tail so that the record will survive for a time under LRU cache algorithm removing records from the head.

The function `tcmdbvsiz' is used in order to get the size of the value of a record in an on-memory database object.


int tcmdbvsiz(TCMDB *mdb, const void *kbuf, int ksiz);
`mdb' specifies the on-memory database object.
`kbuf' specifies the pointer to the region of the key.
`ksiz' specifies the size of the region of the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

The function `tcmdbvsiz2' is used in order to get the size of the value of a string record in an on-memory database object.


int tcmdbvsiz2(TCMDB *mdb, const char *kstr);
`mdb' specifies the on-memory database object.
`kstr' specifies the string of the key.
If successful, the return value is the size of the value of the corresponding record, else, it is -1.

The function `tcmdbiterinit' is used in order to initialize the iterator of an on-memory database object.


void tcmdbiterinit(TCMDB *mdb);
`mdb' specifies the on-memory database object.
The iterator is used in order to access the key of every record stored in the on-memory database.

The function `tcmdbiternext' is used in order to get the next key of the iterator of an on-memory database object.


void *tcmdbiternext(TCMDB *mdb, int *sp);
`mdb' specifies the on-memory database object.
`sp' specifies the pointer to the variable into which the size of the region of the return
value is assigned.
If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. The order of iteration is assured to be the same as the stored order.

The function `tcmdbiternext2' is used in order to get the next key string of the iterator of an on-memory database object.


char *tcmdbiternext2(TCMDB *mdb);
`mdb' specifies the on-memory database object.
If successful, the return value is the pointer to the region of the next key, else, it is `NULL'. `NULL' is returned when no record can be fetched from the iterator.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use. The order of iteration is assured to be the same as the stored order.

The function `tcmdbfwmkeys' is used in order to get forward matching keys in an on-memory database object.


TCLIST *tcmdbfwmkeys(TCMDB *mdb, const void *pbuf, int psiz, int max);
`mdb' specifies the on-memory database object.
`pbuf' specifies the pointer to the region of the prefix.
`psiz' specifies the size of the region of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the corresponding keys. This function does never fail and return an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. Note that this function may be very slow because every key in the database is scanned.

The function `tcmdbfwmkeys2' is used in order to get forward matching string keys in an on-memory database object.


TCLIST *tcmdbfwmkeys2(TCMDB *mdb, const char *pstr, int max);
`mdb' specifies the on-memory database object.
`pstr' specifies the string of the prefix.
`max' specifies the maximum number of keys to be fetched. If it is negative, no limit is specified.
The return value is a list object of the corresponding keys. This function does never fail and return an empty list even if no key corresponds.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. Note that this function may be very slow because every key in the database is scanned.

The function `tcmdbrnum' is used in order to get the number of records stored in an on-memory database object.


uint64_t tcmdbrnum(TCMDB *mdb);
`mdb' specifies the on-memory database object.
The return value is the number of the records stored in the database.

The function `tcmdbmsiz' is used in order to get the total size of memory used in an on-memory database object.


uint64_t tcmdbmsiz(TCMDB *mdb);
`mdb' specifies the on-memory database object.
The return value is the total size of memory used in the database.

The function `tcmdbvanish' is used in order to clear an on-memory database object.


void tcmdbvanish(TCMDB *mdb);
`mdb' specifies the on-memory database object.
All records are removed.

The function `tcmdbcutfront' is used in order to remove front records of an on-memory database object.


void tcmdbcutfront(TCMDB *mdb, int num);
`mdb' specifies the on-memory database object.
`num' specifies the number of records to be removed.
If successful, the return value is true. False is returned when no record corresponds to the specified key.

API OF MEMORY POOL

The function `tcmpoolnew' is used in order to create a memory pool object.


TCMPOOL *tcmpoolnew(void);
The return value is the new memory pool object.

The function `tcmpooldel' is used in order to delete a memory pool object.


void tcmpooldel(TCMPOOL *mpool);
`mpool' specifies the memory pool object.
Note that the deleted object and its derivatives can not be used anymore.

The function `tcmpoolput' is used in order to relegate an arbitrary object to a memory pool object.


void tcmpoolput(TCMPOOL *mpool, void *ptr, void (*del)(void *));
`mpool' specifies the memory pool object.
`ptr' specifies the pointer to the object to be relegated.
`del' specifies the pointer to the function to delete the object.
This function assures that the specified object is deleted when the memory pool object is deleted.

The function `tcmpoolputptr' is used in order to relegate an allocated region to a memory pool object.


void tcmpoolputptr(TCMPOOL *mpool, void *ptr);
`ptr' specifies the pointer to the region to be relegated.
This function assures that the specified region is released when the memory pool object is deleted.

The function `tcmpoolputxstr' is used in order to relegate an extensible string object to a memory pool object.


void tcmpoolputxstr(TCMPOOL *mpool, TCXSTR *xstr);
`mpool' specifies the memory pool object.
`xstr' specifies the extensible string object.
This function assures that the specified object is deleted when the memory pool object is deleted.

The function `tcmpoolputlist' is used in order to relegate a list object to a memory pool object.


void tcmpoolputlist(TCMPOOL *mpool, TCLIST *list);
`mpool' specifies the memory pool object.
`list' specifies the list object.
This function assures that the specified object is deleted when the memory pool object is deleted.

The function `tcmpoolputmap' is used in order to relegate a map object to a memory pool object.


void tcmpoolputmap(TCMPOOL *mpool, TCMAP *map);
`mpool' specifies the memory pool object.
`map' specifies the map object.
This function assures that the specified object is deleted when the memory pool object is deleted.

The function `tcmpoolmalloc' is used in order to allocate a region relegated to a memory pool object.


void *tcmpoolmalloc(TCMPOOL *mpool, size_t size);
`mpool' specifies the memory pool object.
The return value is the pointer to the allocated region under the memory pool.

The function `tcmpoolxstrnew' is used in order to create an extensible string object relegated to a memory pool object.


TCXSTR *tcmpoolxstrnew(TCMPOOL *mpool);
The return value is the new extensible string object under the memory pool.

The function `tcmpoollistnew' is used in order to create a list object relegated to a memory pool object.


TCLIST *tcmpoollistnew(TCMPOOL *mpool);
The return value is the new list object under the memory pool.

The function `tcmpoolmapnew' is used in order to create a map object relegated to a memory pool object.


TCMAP *tcmpoolmapnew(TCMPOOL *mpool);
The return value is the new map object under the memory pool.

The function `tcmpoolglobal' is used in order to get the global memory pool object.


TCMPOOL *tcmpoolglobal(void);
The return value is the global memory pool object.
The global memory pool object is a singleton and assured to be deleted when the process is terminating normally.

API OF MISCELLANEOUS UTILITIES

The function `tclmax' is used in order to get the larger value of two integers.


long tclmax(long a, long b);
`a' specifies an integer.
`b' specifies the other integer.
The return value is the larger value of the two.

The function `tclmin' is used in order to get the lesser value of two integers.


long tclmin(long a, long b);
`a' specifies an integer.
`b' specifies the other integer.
The return value is the lesser value of the two.

The function `tclrand' is used in order to get a random number as long integer based on uniform distribution.


unsigned long tclrand(void);
The return value is the random number between 0 and `ULONG_MAX'.
This function uses the random number source device and generates a real random number if possible.

The function `tcdrand' is used in order to get a random number as double decimal based on uniform distribution.


double tcdrand(void);
The return value is the random number equal to or greater than 0, and less than 1.0.
This function uses the random number source device and generates a real random number if possible.

The function `tcdrandnd' is used in order to get a random number as double decimal based on normal distribution.


double tcdrandnd(double avg, double sd);
`avg' specifies the average.
`sd' specifies the standard deviation.
The return value is the random number.
This function uses the random number source device and generates a real random number if possible.

The function `tcstricmp' is used in order to compare two strings with case insensitive evaluation.


int tcstricmp(const char *astr, const char *bstr);
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is positive if the former is big, negative if the latter is big, 0 if both are equivalent.

The function `tcstrfwm' is used in order to check whether a string begins with a key.


bool tcstrfwm(const char *str, const char *key);
`str' specifies the target string.
`key' specifies the forward matching key string.
The return value is true if the target string begins with the key, else, it is false.

The function `tcstrifwm' is used in order to check whether a string begins with a key with case insensitive evaluation.


bool tcstrifwm(const char *str, const char *key);
`str' specifies the target string.
`key' specifies the forward matching key string.
The return value is true if the target string begins with the key, else, it is false.

The function `tcstrbwm' is used in order to check whether a string ends with a key.


bool tcstrbwm(const char *str, const char *key);
`str' specifies the target string.
`key' specifies the backward matching key string.
The return value is true if the target string ends with the key, else, it is false.

The function `tcstribwm' is used in order to check whether a string ends with a key with case insensitive evaluation.


bool tcstribwm(const char *str, const char *key);
`str' specifies the target string.
`key' specifies the backward matching key string.
The return value is true if the target string ends with the key, else, it is false.

The function `tcstrdist' is used in order to calculate the edit distance of two strings.


int tcstrdist(const char *astr, const char *bstr);
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is the edit distance which is known as the Levenshtein distance. The cost is calculated by byte.

The function `tcstrdistutf' is used in order to calculate the edit distance of two UTF-8 strings.


int tcstrdistutf(const char *astr, const char *bstr);
`astr' specifies a string.
`bstr' specifies of the other string.
The return value is the edit distance which is known as the Levenshtein distance. The cost is calculated by Unicode character.

The function `tcstrtoupper' is used in order to convert the letters of a string into upper case.


char *tcstrtoupper(char *str);
`str' specifies the string to be converted.
The return value is the string itself.

The function `tcstrtolower' is used in order to convert the letters of a string into lower case.


char *tcstrtolower(char *str);
`str' specifies the string to be converted.
The return value is the string itself.

The function `tcstrtrim' is used in order to cut space characters at head or tail of a string.


char *tcstrtrim(char *str);
`str' specifies the string to be converted.
The return value is the string itself.

The function `tcstrsqzspc' is used in order to squeeze space characters in a string and trim it.


char *tcstrsqzspc(char *str);
`str' specifies the string to be converted.
The return value is the string itself.

The function `tcstrsubchr' is used in order to substitute characters in a string.


char *tcstrsubchr(char *str, const char *rstr, const char *sstr);
`str' specifies the string to be converted.
`rstr' specifies the string containing characters to be replaced.
`sstr' specifies the string containing characters to be substituted.
If the substitute string is shorter then the replacement string, corresponding characters are removed.

The function `tcstrcntutf' is used in order to count the number of characters in a string of UTF-8.


int tcstrcntutf(const char *str);
`str' specifies the string of UTF-8.
The return value is the number of characters in the string.

The function `tcstrcututf' is used in order to cut a string of UTF-8 at the specified number of characters.


char *tcstrcututf(char *str, int num);
`str' specifies the string of UTF-8.
`num' specifies the number of characters to be kept.
The return value is the string itself.

The function `tcstrutftoucs' is used in order to convert a UTF-8 string into a UCS-2 array.


void tcstrutftoucs(const char *str, uint16_t *ary, int *np);
`str' specifies the UTF-8 string.
`ary' specifies the pointer to the region into which the result UCS-2 codes are written. The size of the buffer should be sufficient.
`np' specifies the pointer to a variable into which the number of elements of the result array is assigned.

The function `tcstrucstoutf' is used in order to convert a UCS-2 array into a UTF-8 string.


void tcstrucstoutf(const uint16_t *ary, int num, char *str);
`ary' specifies the array of UCS-2 code codes.
`num' specifies the number of the array.
`str' specifies the pointer to the region into which the result UTF-8 string is written. The size of the buffer should be sufficient.

The function `tcstrsplit' is used in order to create a list object by splitting a string.


TCLIST *tcstrsplit(const char *str, const char *delims);
`str' specifies the source string.
`delims' specifies a string containing delimiting characters.
The return value is a list object of the split elements.
If two delimiters are successive, it is assumed that an empty element is between the two. Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

The function `tcstrjoin' is used in order to create a string by joining all elements of a list object.


char *tcstrjoin(TCLIST *list, char delim);
`list' specifies a list object.
`delim' specifies a delimiting character.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tctime' is used in order to get the time of day in seconds.


double tctime(void);
The return value is the time of day in seconds. The accuracy is in microseconds.

The function `tccalendar' is used in order to get the Gregorian calendar of a time.


void tccalendar(int64_t t, int jl, int *yearp, int *monp, int *dayp, int *hourp, int *minp, int *secp);
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is specified.
`yearp' specifies the pointer to a variable to which the year is assigned. If it is `NULL', it is not used.
`monp' specifies the pointer to a variable to which the month is assigned. If it is `NULL', it is not used. 1 means January and 12 means December.
`dayp' specifies the pointer to a variable to which the day of the month is assigned. If it is `NULL', it is not used.
`hourp' specifies the pointer to a variable to which the hours is assigned. If it is `NULL', it is not used.
`minp' specifies the pointer to a variable to which the minutes is assigned. If it is `NULL', it is not used.
`secp' specifies the pointer to a variable to which the seconds is assigned. If it is `NULL', it is not used.

The function `tcdatestrwww' is used in order to format a date as a string in W3CDTF.


void tcdatestrwww(int64_t t, int jl, char *buf);
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is specified.
`buf' specifies the pointer to the region into which the result string is written. The size of the buffer should be equal to or more than 48 bytes.
W3CDTF represents a date as "YYYY-MM-DDThh:mm:ddTZD".

The function `tcdatestrhttp' is used in order to format a date as a string in RFC 1123 format.


void tcdatestrhttp(int64_t t, int jl, char *buf);
`t' specifies the source time in seconds from the epoch. If it is `INT64_MAX', the current time is specified.
`jl' specifies the jet lag of a location in seconds. If it is `INT_MAX', the local jet lag is specified.
`buf' specifies the pointer to the region into which the result string is written. The size of the buffer should be equal to or more than 48 bytes.
RFC 1123 format represents a date as "Wdy, DD-Mon-YYYY hh:mm:dd TZD".

The function `tcstrmktime' is used in order to get the time value of a date string.


int64_t tcstrmktime(const char *str);
`str' specifies the date string in decimal, hexadecimal, W3CDTF, or RFC 822 (1123). Decimal can be trailed by "s" for in seconds, "m" for in minutes, "h" for in hours, and "d" for in days.
The return value is the time value of the date or `INT64_MAX' if the format is invalid.

The function `tcdayofweek' is used in order to get the day of week of a date.


int tcdayofweek(int year, int mon, int day);
`year' specifies the year of a date.
`mon' specifies the month of the date.
`day' specifies the day of the date.
The return value is the day of week of the date. 0 means Sunday and 6 means Saturday.

API OF FILESYSTEM UTILITIES

The function `tcrealpath' is used in order to get the canonicalized absolute path of a file.


char *tcrealpath(const char *path);
`path' specifies the path of the file.
The return value is the canonicalized absolute path of a file, or `NULL' if the path is invalid.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcreadfile' is used in order to read whole data of a file.


void *tcreadfile(const char *path, int limit, int *sp);
`path' specifies the path of the file. If it is `NULL', the standard input is specified.
`limit' specifies the limiting size of reading data. If it is not more than 0, the limitation is not specified.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned. If it is `NULL', it is not used.
The return value is the pointer to the allocated region of the read data, or `NULL' if the file could not be opened.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when when is no longer in use.

The function `tcreadfilelines' is used in order to read every line of a file.


TCLIST *tcreadfilelines(const char *path);
`path' specifies the path of the file. If it is `NULL', the standard input is specified.
The return value is a list object of every lines if successful, else it is `NULL'.
Line separators are cut out. Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

The function `tcwritefile' is used in order to write data into a file.


bool tcwritefile(const char *path, const void *ptr, int size);
`path' specifies the path of the file. If it is `NULL', the standard output is specified.
`ptr' specifies the pointer to the data region.
`size' specifies the size of the region.
If successful, the return value is true, else, it is false.

The function `tccopyfile' is used in order to copy a file.


bool tccopyfile(const char *src, const char *dest);
`src' specifies the path of the source file.
`dest' specifies the path of the destination file.
The return value is true if successful, else, it is false.
If the destination file exists, it is overwritten.

The function `tcreaddir' is used in order to read names of files in a directory.


TCLIST *tcreaddir(const char *path);
`path' specifies the path of the directory.
The return value is a list object of names if successful, else it is `NULL'.
Links to the directory itself and to the parent directory are ignored.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use.

The function `tcremovelink' is used in order to remove a file or a directory and its sub ones recursively.


bool tcremovelink(const char *path);
`path' specifies the path of the link.
If successful, the return value is true, else, it is false. False is returned when the link does not exist or the permission is denied.

The function `tcwrite' is used in order to write data into a file.


bool tcwrite(int fd, const void *buf, size_t size);
`fd' specifies the file descriptor.
`buf' specifies the buffer to be written.
`size' specifies the size of the buffer.
The return value is true if successful, else, it is false.

The function `tcread' is used in order to read data from a file.


bool tcread(int fd, void *buf, size_t size);
`fd' specifies the file descriptor.
`buf' specifies the buffer to store into.
`size' specifies the size of the buffer.
The return value is true if successful, else, it is false.

The function `tclock' is used in order to lock a file.


bool tclock(int fd, bool ex, bool nb);
`fd' specifies the file descriptor.
`ex' specifies whether an exclusive lock or a shared lock is performed.
`nb' specifies whether to request with non-blocking.
The return value is true if successful, else, it is false.

API OF ENCODING UTILITIES

The function `tcurlencode' is used in order to encode a serial object with URL encoding.


char *tcurlencode(const char *ptr, int size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use.

The function `tcurldecode' is used in order to decode a string encoded with URL encoding.


char *tcurldecode(const char *str, int *sp);
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcurlbreak' is used in order to break up a URL into elements.


TCMAP *tcurlbreak(const char *str);
`str' specifies the URL string.
The return value is the map handle whose keys are the name of elements. The key "self" specifies the URL itself. The key "scheme" specifies the scheme. The key "host" specifies the host of the server. The key "port" specifies the port number of the server. The key "authority" specifies the authority information. The key "path" specifies the path of the resource. The key "file" specifies the file name without the directory section. The key "query" specifies the query string. The key "fragment" specifies the fragment string.
Supported schema are HTTP, HTTPS, FTP, and FILE. Absolute URL and relative URL are supported. Because the object of the return value is created with the function `tcmapnew', it should be deleted with the function `tcmapdel' when it is no longer in use.

The function `tcurlresolve' is used in order to resolve a relative URL with an absolute URL.


char *tcurlresolve(const char *base, const char *target);
`base' specifies the absolute URL of the base location.
`target' specifies the URL to be resolved.
The return value is the resolved URL. If the target URL is relative, a new URL of relative location from the base location is returned. Else, a copy of the target URL is returned.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcbaseencode' is used in order to encode a serial object with Base64 encoding.


char *tcbaseencode(const char *ptr, int size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use.

The function `tcbasedecode' is used in order to decode a string encoded with Base64 encoding.


char *tcbasedecode(const char *str, int *sp);
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcquoteencode' is used in order to encode a serial object with Quoted-printable encoding.


char *tcquoteencode(const char *ptr, int size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use.

The function `tcquotedecode' is used in order to decode a string encoded with Quoted-printable encoding.


char *tcquotedecode(const char *str, int *sp);
`str' specifies the encoded string.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmimeencode' is used in order to encode a string with MIME encoding.


char *tcmimeencode(const char *str, const char *encname, bool base);
`str' specifies the string.
`encname' specifies the string of the name of the character encoding.
`base' specifies whether to use Base64 encoding. If it is false, Quoted-printable is used.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcmimedecode' is used in order to decode a string encoded with MIME encoding.


char *tcmimedecode(const char *str, char *enp);
`str' specifies the encoded string.
`enp' specifies the pointer to the region into which the name of encoding is written. If it is `NULL', it is not used. The size of the buffer should be equal to or more than 32 bytes.
The return value is the result string.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcpackencode' is used in order to compress a serial object with Packbits encoding.


char *tcpackencode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcpackdecode' is used in order to decompress a serial object compressed with Packbits encoding.


char *tcpackdecode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcbsencode' is used in order to compress a serial object with TCBS encoding.


char *tcbsencode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcbsdecode' is used in order to decompress a serial object compressed with TCBS encoding.


char *tcbsdecode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcdeflate' is used in order to compress a serial object with Deflate encoding.


char *tcdeflate(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcinflate' is used in order to decompress a serial object compressed with Deflate encoding.


char *tcinflate(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcgzipencode' is used in order to compress a serial object with GZIP encoding.


char *tcgzipencode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to the variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcgzipdecode' is used in order to decompress a serial object compressed with GZIP encoding.


char *tcgzipdecode(const char *ptr, int size, int *sp);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
If successful, the return value is the pointer to the result object, else, it is `NULL'.
Because an additional zero code is appended at the end of the region of the return value, the return value can be treated as a character string. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcgetcrc' is used in order to get the CRC32 checksum of a serial object.


unsigned int tcgetcrc(const char *ptr, int size);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
The return value is the CRC32 checksum of the object.

The function `tcberencode' is used in order to encode an array of nonnegative integers with BER encoding.


char *tcberencode(const unsigned int *ary, int anum, int *sp);
`ary' specifies the pointer to the array of nonnegative integers.
`anum' specifies the size of the array.
`sp' specifies the pointer to a variable into which the size of the region of the return value is assigned.
The return value is the pointer to the region of the result.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use.

The function `tcberdecode' is used in order to decode a serial object encoded with BER encoding.


unsigned int *tcberdecode(const char *ptr, int size, int *np);
`ptr' specifies the pointer to the region.
`size' specifies the size of the region.
`np' specifies the pointer to a variable into which the number of elements of the return value is assigned.
The return value is the pointer to the array of the result.
Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call if when is no longer in use.

The function `tcxmlescape' is used in order to escape meta characters in a string with the entity references of XML.


char *tcxmlescape(const char *str);
`str' specifies the string.
The return value is the pointer to the escaped string.
This function escapes only `&', `<', `>', and `"'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcxmlunescape' is used in order to unescape entity references in a string of XML.


char *tcxmlunescape(const char *str);
`str' specifies the string.
The return value is the unescaped string.
This function restores only `&amp;', `&lt;', `&gt;', and `&quot;'. Because the region of the return value is allocated with the `malloc' call, it should be released with the `free' call when it is no longer in use.

The function `tcxmlbreak' is used in order to split an XML string into tags and text sections.


TCLIST *tcxmlbreak(const char *str);
`str' specifies the XML string.
The return value is the list object whose elements are strings of tags or text sections.
Because the object of the return value is created with the function `tclistnew', it should be deleted with the function `tclistdel' when it is no longer in use. Because this function does not check validation, it can handle also HTML and SGML.

The function `tcxmlattrs' is used in order to get the map of attributes of an XML tag.


TCMAP *tcxmlattrs(const char *str);
`str' specifies the pointer to the region of a tag string.
The return value is the map object containing attribute names and their values which are unescaped. You can get the name of the tag with the key of an empty string.
Because the object of the return value is created with the function `tcmapnew', it should be deleted with the function `tcmapdel' when it is no longer in use.

SEE ALSO

tcutest(1), tcucodec(1), tokyocabinet(3)