diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-05-12 17:23:29 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2008-05-12 17:23:29 +0400 |
commit | 2da7593c289cb3480ced048c8068ebc3a3119fd8 (patch) | |
tree | 417cfb5c943d8fd17b15ff6df4ed84581861e345 /fstring.h | |
parent | 70c78281e3957bdbaa1204e40f2419a4a1918eb7 (diff) | |
download | rspamd-2da7593c289cb3480ced048c8068ebc3a3119fd8.tar.gz rspamd-2da7593c289cb3480ced048c8068ebc3a3119fd8.zip |
* Add fixed string library
Diffstat (limited to 'fstring.h')
-rw-r--r-- | fstring.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/fstring.h b/fstring.h new file mode 100644 index 000000000..30895ccc5 --- /dev/null +++ b/fstring.h @@ -0,0 +1,77 @@ +/* + * Functions for handling with fixed size strings + */ + +#ifndef FSTRING_H +#define FSTRING_H + +#include <sys/types.h> + +typedef struct f_str_s { + char *begin; + size_t len; + size_t size; +} f_str_t; + +typedef struct f_tok_s { + f_str_t word; + size_t pos; +} f_tok_t; + +/* + * Search first occurence of character in string + */ +ssize_t fstrchr (f_str_t *src, char c); + +/* + * Search last occurence of character in string + */ +ssize_t fstrrchr (f_str_t *src, char c); + +/* + * Search for pattern in orig + */ +ssize_t fstrstr (f_str_t *orig, f_str_t *pattern); + +/* + * Split string by tokens + * word contains parsed word + */ +int fstrtok (f_str_t *text, const char *sep, f_tok_t *state); + +/* + * Copy one string into other + */ +size_t fstrcpy (f_str_t *dest, f_str_t *src); + +/* + * Concatenate two strings + */ +size_t fstrcat (f_str_t *dest, f_str_t *src); + +/* + * Push one character to fstr + */ +int fstrpush (f_str_t *dest, char c); + +/* + * Allocate memory for f_str_t + */ +f_str_t* fstralloc (size_t len); + +/* + * Truncate string to its len + */ +f_str_t* fstrtruncate (f_str_t *orig); + +/* + * Enlarge string to new size + */ +f_str_t* fstrgrow (f_str_t *orig, size_t newlen); + +/* + * Free memory for f_str_t + */ +#define fstrfree(x) free((x)->begin); free((x)) + +#endif |