Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/strfuncs.h @ 9658:8ba4253adc9b HEAD tip
*-login: SSL connections didn't get closed when the client got destroyed.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 May 2014 16:41:29 +0300 |
parents | 1789ac4637b0 |
children |
rev | line source |
---|---|
6410
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5681
diff
changeset
|
1 #ifndef STRFUNC_H |
e4eb71ae8e96
Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents:
5681
diff
changeset
|
2 #define STRFUNC_H |
0 | 3 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
4 #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
|
5 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
6 /* 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
|
7 int i_snprintf(char *dest, size_t max_chars, const char *format, ...) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
8 ATTR_FORMAT(3, 4); |
0 | 9 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
10 char *p_strdup(pool_t pool, const char *str) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
11 /* return NULL if str = "" */ |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
12 char *p_strdup_empty(pool_t pool, const char *str) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
13 /* *end isn't included */ |
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
14 char *p_strdup_until(pool_t pool, const void *start, const void *end) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
15 ATTR_MALLOC; |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
16 char *p_strndup(pool_t pool, const void *str, size_t max_chars) ATTR_MALLOC; |
903
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_printf(pool_t pool, const char *format, ...) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
18 ATTR_FORMAT(2, 3) ATTR_MALLOC; |
4719
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
19 char *p_strdup_vprintf(pool_t pool, const char *format, va_list args) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
20 ATTR_FORMAT(2, 0) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
21 char *p_strconcat(pool_t pool, const char *str1, ...) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
22 ATTR_SENTINEL ATTR_MALLOC; |
0 | 23 |
24 /* same with temporary memory allocations: */ | |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
25 const char *t_strdup(const char *str) ATTR_MALLOC; |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
26 char *t_strdup_noconst(const char *str) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
27 /* return NULL if str = "" */ |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
28 const char *t_strdup_empty(const char *str) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
29 /* *end isn't included */ |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
30 const char *t_strdup_until(const void *start, const void *end) ATTR_MALLOC; |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
31 const char *t_strndup(const void *str, size_t max_chars) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
32 const char *t_strdup_printf(const char *format, ...) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
33 ATTR_FORMAT(1, 2) ATTR_MALLOC; |
4719
1995cb3763db
Added sentinel GCC attribute to *_strconcat() functions. Added
Timo Sirainen <tss@iki.fi>
parents:
4332
diff
changeset
|
34 const char *t_strdup_vprintf(const char *format, va_list args) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
35 ATTR_FORMAT(1, 0) ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
36 const char *t_strconcat(const char *str1, ...) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
37 ATTR_SENTINEL ATTR_MALLOC; |
0 | 38 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
39 /* Like t_strdup(), but stop at cutchar. */ |
0 | 40 const char *t_strcut(const char *str, char cutchar); |
41 | |
42 /* Return TRUE if all characters in string are numbers. | |
43 Stop when `end_char' is found from string. */ | |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
44 bool is_numeric(const char *str, char end_char) ATTR_PURE; |
0 | 45 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
46 /* Like strlcpy(), but return -1 if buffer was overflown, 0 if not. */ |
6422
18173a52f721
Renamed strocpy() to i_strocpy().
Timo Sirainen <tss@iki.fi>
parents:
6421
diff
changeset
|
47 int i_strocpy(char *dest, const char *src, size_t dstsize); |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
48 |
0 | 49 char *str_ucase(char *str); |
50 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
|
51 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
|
52 const char *t_str_ucase(const char *str); |
0 | 53 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
54 int null_strcmp(const char *s1, const char *s2) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
55 int bsearch_strcmp(const void *p1, const void *p2) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
56 int bsearch_strcasecmp(const void *p1, const void *p2) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
57 int i_memcasecmp(const void *p1, const void *p2, size_t size) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
58 int i_strcmp_p(const void *p1, const void *p2) ATTR_PURE; |
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
59 int i_strcasecmp_p(const void *p1, const void *p2) ATTR_PURE; |
898
0d5be52d7131
Use unsigned char* when accessing non-NUL terminating strings. Compiler
Timo Sirainen <tss@iki.fi>
parents:
896
diff
changeset
|
60 |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
61 /* separators is an array of separator characters, not a separator string. */ |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
62 char **p_strsplit(pool_t pool, const char *data, const char *separators) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
63 ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
64 const char **t_strsplit(const char *data, const char *separators) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
65 ATTR_MALLOC; |
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. */ |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
68 char **p_strsplit_spaces(pool_t pool, const char *data, const char *separators) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
69 ATTR_MALLOC; |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
70 const char **t_strsplit_spaces(const char *data, const char *separators) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
71 ATTR_MALLOC; |
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 */ |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
6426
diff
changeset
|
77 unsigned int str_array_length(const char *const *arr) ATTR_PURE; |
3038 | 78 /* Return all strings from array joined into one string. */ |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
79 const char *t_strarray_join(const char *const *arr, const char *separator) |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6410
diff
changeset
|
80 ATTR_MALLOC; |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
81 /* Removes a value from NULL-terminated string array. Returns TRUE if found. */ |
6424
687efa138e77
Renamed strarray_length/remote() to str_array_length/remove()
Timo Sirainen <tss@iki.fi>
parents:
6423
diff
changeset
|
82 bool str_array_remove(const char **arr, const char *value); |
7915 | 83 /* Returns TRUE if value exists in NULL-terminated string array. |
84 Strings are compared case-insensitively. */ | |
85 bool str_array_icase_find(const char *const *arr, const char *value); | |
3014 | 86 |
0 | 87 /* INTERNAL */ |
5681
09415e6a0892
Require C99 compatible vsnprintf(). Removed printf_string_upper_bound() and
Timo Sirainen <tss@iki.fi>
parents:
5679
diff
changeset
|
88 char *t_noalloc_strdup_vprintf(const char *format, va_list args, |
09415e6a0892
Require C99 compatible vsnprintf(). Removed printf_string_upper_bound() and
Timo Sirainen <tss@iki.fi>
parents:
5679
diff
changeset
|
89 unsigned int *size_r); |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
90 char *vstrconcat(const char *str1, va_list args, size_t *ret_len) ATTR_MALLOC; |
0 | 91 |
92 #endif |