Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/strfuncs.h @ 4075:bd7aafc736eb HEAD
Added strcmp_p and bsearch_strcmp.
author | Timo Sirainen <timo.sirainen@movial.fi> |
---|---|
date | Mon, 27 Feb 2006 18:14:55 +0200 |
parents | 55df57c028d4 |
children | 2428e6821eb4 |
rev | line source |
---|---|
0 | 1 #ifndef __STRFUNC_H |
2 #define __STRFUNC_H | |
3 | |
4 #define is_empty_str(str) \ | |
5 ((str) == NULL || (str)[0] == '\0') | |
6 | |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
7 #define MAX_INT_STRLEN ((sizeof(uintmax_t) * CHAR_BIT + 2) / 3 + 1) |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
8 |
833
41ec8cadd238
Replaced TempString with a String which can use any memory pool and uses
Timo Sirainen <tss@iki.fi>
parents:
807
diff
changeset
|
9 const char *printf_string_fix_format(const char *fmt) __attr_format_arg__(1); |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
10 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
11 /* Returns -1 if dest wasn't large enough, 0 if not. */ |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
12 int i_snprintf(char *dest, size_t max_chars, const char *format, ...) |
0 | 13 __attr_format__(3, 4); |
14 | |
903
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
15 char *p_strdup(pool_t pool, const char *str); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
16 char *p_strdup_empty(pool_t pool, const char *str); /* return NULL if str = "" */ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
17 char *p_strdup_until(pool_t pool, const void *start, const void *end); /* *end isn't included */ |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
18 char *p_strndup(pool_t pool, const void *str, size_t max_chars); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
19 char *p_strdup_printf(pool_t pool, const char *format, ...) |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
20 __attr_format__(2, 3); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
21 char *p_strdup_vprintf(pool_t pool, const char *format, va_list args); |
fd8888f6f037
Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents:
898
diff
changeset
|
22 char *p_strconcat(pool_t pool, const char *str1, ...); /* NULL terminated */ |
0 | 23 |
24 /* same with temporary memory allocations: */ | |
25 const char *t_strdup(const char *str); | |
64
83ae914a583a
added t_strdup_noconst() which can be used instead of (char *) t_strdup().
Timo Sirainen <tss@iki.fi>
parents:
56
diff
changeset
|
26 char *t_strdup_noconst(const char *str); |
0 | 27 const char *t_strdup_empty(const char *str); /* return NULL if str = "" */ |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
896
diff
changeset
|
28 const char *t_strdup_until(const void *start, const void *end); /* *end isn't included */ |
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
896
diff
changeset
|
29 const char *t_strndup(const void *str, size_t max_chars); |
0 | 30 const char *t_strdup_printf(const char *format, ...) __attr_format__(1, 2); |
31 const char *t_strdup_vprintf(const char *format, va_list args); | |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
32 const char *t_strconcat(const char *str1, ...); /* NULL terminated */ |
0 | 33 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
34 /* Like t_strdup(), but stop at cutchar. */ |
0 | 35 const char *t_strcut(const char *str, char cutchar); |
36 | |
37 /* Return TRUE if all characters in string are numbers. | |
38 Stop when `end_char' is found from string. */ | |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3615
diff
changeset
|
39 bool is_numeric(const char *str, char end_char); |
0 | 40 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
41 /* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */ |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
42 int strocpy(char *dest, const char *src, size_t dstsize); |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
43 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
44 /* Print given directory and file to dest buffer, separated with '/'. |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
45 If destination buffer is too small, it's set to empty string and errno is |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
46 set to ENAMETOOLONG. Retuns -1 if buffer is too small, or 0 if not. */ |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
47 int str_path(char *dest, size_t dstsize, const char *dir, const char *file); |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
48 int str_ppath(char *dest, size_t dstsize, const char *dir, |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
49 const char *file_prefix, const char *file); |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
50 |
0 | 51 char *str_ucase(char *str); |
52 char *str_lcase(char *str); | |
2057
5e0167577399
Fixed var_expand() to take a table of variables rather than a few predefined
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
53 const char *t_str_lcase(const char *str); |
5e0167577399
Fixed var_expand() to take a table of variables rather than a few predefined
Timo Sirainen <tss@iki.fi>
parents:
1820
diff
changeset
|
54 const char *t_str_ucase(const char *str); |
0 | 55 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
56 int null_strcmp(const char *s1, const char *s2); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
896
diff
changeset
|
57 int memcasecmp(const void *p1, const void *p2, size_t size); |
4075
bd7aafc736eb
Added strcmp_p and bsearch_strcmp.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3863
diff
changeset
|
58 int bsearch_strcmp(const void *p1, const void *p2); |
bd7aafc736eb
Added strcmp_p and bsearch_strcmp.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3863
diff
changeset
|
59 int strcmp_p(const void *p1, const void *p2); |
2195 | 60 int bsearch_strcasecmp(const void *p1, const void *p2); |
2421
d141e1bfdd63
We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents:
2195
diff
changeset
|
61 int strcasecmp_p(const void *p1, const void *p2); |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
896
diff
changeset
|
62 |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
63 /* separators is an array of separator characters, not a separator string. */ |
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
64 char **p_strsplit(pool_t pool, const char *data, const char *separators); |
847
7f41a4b33975
t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
65 const char **t_strsplit(const char *data, const char *separators); |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
66 /* like p_strsplit(), but treats multiple adjacent separators as a single |
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
67 separator. */ |
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
68 char **p_strsplit_spaces(pool_t pool, const char *data, |
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
69 const char *separators); |
1820 | 70 const char **t_strsplit_spaces(const char *data, const char *separators); |
0 | 71 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
72 const char *dec2str(uintmax_t number); |
179
0ffecd4e7e1a
added dec2str() function and largest_t type, removed itoa() and ltoa()
Timo Sirainen <tss@iki.fi>
parents:
64
diff
changeset
|
73 |
3014 | 74 /* Return length of NULL-terminated list string array */ |
75 unsigned int strarray_length(const char *const *arr); | |
3038 | 76 /* Return all strings from array joined into one string. */ |
3061
42c1ca1f7a45
Renamed strarray_join() to t_strarray_join() and made it not to crash..
Timo Sirainen <tss@iki.fi>
parents:
3038
diff
changeset
|
77 const char *t_strarray_join(const char *const *arr, const char *separator); |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
78 /* Removes a value from NULL-terminated string array. Returns TRUE if found. */ |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3615
diff
changeset
|
79 bool strarray_remove(const char **arr, const char *value); |
3014 | 80 |
0 | 81 /* INTERNAL */ |
3385
fe4a297379fc
If p_malloc() used data stack (with DEBUG enabled it might have written a
Timo Sirainen <tss@iki.fi>
parents:
3061
diff
changeset
|
82 char *_vstrconcat(const char *str1, va_list args, size_t *ret_len); |
0 | 83 |
84 #endif |