Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/strfuncs.h @ 4719:1995cb3763db HEAD
Added sentinel GCC attribute to *_strconcat() functions. Added
format printf-attribute to vprintf-type functions.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 01 Nov 2006 20:47:37 +0200 |
parents | 2428e6821eb4 |
children | b0daeec3d416 |
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); |
4719
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
21 char *p_strdup_vprintf(pool_t pool, const char *format, va_list args) |
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
22 __attr_format__(2, 0); |
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
23 char *p_strconcat(pool_t pool, const char *str1, ...) __attr_sentinel__; |
0 | 24 |
25 /* same with temporary memory allocations: */ | |
26 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
|
27 char *t_strdup_noconst(const char *str); |
0 | 28 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
|
29 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
|
30 const char *t_strndup(const void *str, size_t max_chars); |
0 | 31 const char *t_strdup_printf(const char *format, ...) __attr_format__(1, 2); |
4719
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
32 const char *t_strdup_vprintf(const char *format, va_list args) |
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
33 __attr_format__(1, 0); |
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
34 const char *t_strconcat(const char *str1, ...) __attr_sentinel__; |
0 | 35 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
36 /* Like t_strdup(), but stop at cutchar. */ |
0 | 37 const char *t_strcut(const char *str, char cutchar); |
38 | |
39 /* Return TRUE if all characters in string are numbers. | |
40 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
|
41 bool is_numeric(const char *str, char end_char); |
0 | 42 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
43 /* 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
|
44 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
|
45 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
46 /* 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 |
0 | 53 char *str_ucase(char *str); |
54 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
|
55 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
|
56 const char *t_str_ucase(const char *str); |
0 | 57 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
58 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
|
59 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
|
60 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
|
61 int strcmp_p(const void *p1, const void *p2); |
2195 | 62 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
|
63 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
|
64 |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
65 /* 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
|
66 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
|
67 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
|
68 /* 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
|
69 separator. */ |
4332
2428e6821eb4
Added p_strsplit_free()
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4075
diff
changeset
|
70 char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators); |
1820 | 71 const char **t_strsplit_spaces(const char *data, const char *separators); |
4332
2428e6821eb4
Added p_strsplit_free()
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4075
diff
changeset
|
72 void p_strsplit_free(pool_t pool, char **arr); |
0 | 73 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
74 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
|
75 |
3014 | 76 /* Return length of NULL-terminated list string array */ |
77 unsigned int strarray_length(const char *const *arr); | |
3038 | 78 /* 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
|
79 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
|
80 /* 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
|
81 bool strarray_remove(const char **arr, const char *value); |
3014 | 82 |
0 | 83 /* 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
|
84 char *_vstrconcat(const char *str1, va_list args, size_t *ret_len); |
0 | 85 |
86 #endif |