Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/strfuncs.h @ 6423:13b0a3ba5f7b HEAD
Added i_ prefix to strcmp_p(), strcasecmp_p() and memcasecmp().
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 16 Sep 2007 13:32:59 +0300 |
parents | 18173a52f721 |
children | 687efa138e77 |
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. */ | |
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
|
44 bool is_numeric(const char *str, char end_char); |
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 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
49 /* 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 |
0 | 56 char *str_ucase(char *str); |
57 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
|
58 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
|
59 const char *t_str_ucase(const char *str); |
0 | 60 |
988
8028c4dcf38f
mail-storage.h interface changes, affects pretty much everything.
Timo Sirainen <tss@iki.fi>
parents:
903
diff
changeset
|
61 int null_strcmp(const char *s1, const char *s2); |
4075
bd7aafc736eb
Added strcmp_p and bsearch_strcmp.
Timo Sirainen <timo.sirainen@movial.fi>
parents:
3863
diff
changeset
|
62 int bsearch_strcmp(const void *p1, const void *p2); |
2195 | 63 int bsearch_strcasecmp(const void *p1, const void *p2); |
6423
13b0a3ba5f7b
Added i_ prefix to strcmp_p(), strcasecmp_p() and memcasecmp().
Timo Sirainen <tss@iki.fi>
parents:
6422
diff
changeset
|
64 int i_memcasecmp(const void *p1, const void *p2, size_t size); |
13b0a3ba5f7b
Added i_ prefix to strcmp_p(), strcasecmp_p() and memcasecmp().
Timo Sirainen <tss@iki.fi>
parents:
6422
diff
changeset
|
65 int i_strcmp_p(const void *p1, const void *p2); |
13b0a3ba5f7b
Added i_ prefix to strcmp_p(), strcasecmp_p() and memcasecmp().
Timo Sirainen <tss@iki.fi>
parents:
6422
diff
changeset
|
66 int i_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
|
67 |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
68 /* 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
|
69 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
|
70 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
|
71 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
|
72 ATTR_MALLOC; |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
73 /* 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
|
74 separator. */ |
4720
b0daeec3d416
Use malloc attribute for the most commonly used memory and string allocation
Timo Sirainen <tss@iki.fi>
parents:
4719
diff
changeset
|
75 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
|
76 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
|
77 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
|
78 ATTR_MALLOC; |
4332
2428e6821eb4
Added p_strsplit_free()
Timo Sirainen <timo.sirainen@movial.fi>
parents:
4075
diff
changeset
|
79 void p_strsplit_free(pool_t pool, char **arr); |
0 | 80 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
81 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
|
82 |
3014 | 83 /* Return length of NULL-terminated list string array */ |
84 unsigned int strarray_length(const char *const *arr); | |
3038 | 85 /* 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
|
86 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
|
87 ATTR_MALLOC; |
3615
0a885029543b
Added p_strsplit(), p_strsplit_spaces() and strarray_remove()
Timo Sirainen <tss@iki.fi>
parents:
3385
diff
changeset
|
88 /* 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
|
89 bool strarray_remove(const char **arr, const char *value); |
3014 | 90 |
0 | 91 /* INTERNAL */ |
5681
09415e6a0892
Require C99 compatible vsnprintf(). Removed printf_string_upper_bound() and
Timo Sirainen <tss@iki.fi>
parents:
5679
diff
changeset
|
92 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
|
93 unsigned int *size_r); |
6418
46d9ee79f292
Removed _ prefix from all public APIs.
Timo Sirainen <tss@iki.fi>
parents:
6411
diff
changeset
|
94 char *vstrconcat(const char *str1, va_list args, size_t *ret_len) ATTR_MALLOC; |
0 | 95 |
96 #endif |