Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/lib/strfuncs.h @ 896:21ffcce83c70 HEAD
Rewrote rfc822-tokenize.c to work one token at a time so it won't uselessly
take memory, maybe also a bit faster. This caused pretty large changes all
around.
Also moved all string (un)escaping code to lib/strescape.c.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 03 Jan 2003 17:57:12 +0200 |
parents | 7f41a4b33975 |
children | 0d5be52d7131 |
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 | |
15 char *p_strdup(Pool pool, const char *str); | |
16 char *p_strdup_empty(Pool pool, const char *str); /* return NULL if str = "" */ | |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
17 char *p_strdup_until(Pool pool, const char *start, const char *end); /* *end isn't included */ |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
179
diff
changeset
|
18 char *p_strndup(Pool pool, const char *str, size_t max_chars); |
0 | 19 char *p_strdup_printf(Pool pool, const char *format, ...) __attr_format__(2, 3); |
20 char *p_strdup_vprintf(Pool pool, const char *format, va_list args); | |
21 char *p_strconcat(Pool pool, const char *str1, ...); /* NULL terminated */ | |
22 | |
23 /* same with temporary memory allocations: */ | |
24 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
|
25 char *t_strdup_noconst(const char *str); |
0 | 26 const char *t_strdup_empty(const char *str); /* return NULL if str = "" */ |
5
1b34ec11fff8
Message data is parsed in blocks (no longer entirely mmap()ed). Several
Timo Sirainen <tss@iki.fi>
parents:
0
diff
changeset
|
27 const char *t_strdup_until(const char *start, const char *end); /* *end isn't included */ |
183
4a7ab9e94f25
size_t fixes for lib/. Changed OFF_T_FORMAT to PRIuOFF_T which is more
Timo Sirainen <tss@iki.fi>
parents:
179
diff
changeset
|
28 const char *t_strndup(const char *str, size_t max_chars); |
0 | 29 const char *t_strdup_printf(const char *format, ...) __attr_format__(1, 2); |
30 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
|
31 const char *t_strconcat(const char *str1, ...); /* NULL terminated */ |
0 | 32 |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
33 /* Like t_strdup(), but stop at cutchar. */ |
0 | 34 const char *t_strcut(const char *str, char cutchar); |
35 | |
36 /* Return TRUE if all characters in string are numbers. | |
37 Stop when `end_char' is found from string. */ | |
38 int is_numeric(const char *str, char end_char); | |
39 | |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
40 /* 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
|
41 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
|
42 |
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
43 /* 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 |
0 | 50 char *str_ucase(char *str); |
51 char *str_lcase(char *str); | |
52 | |
53 /* seprators is an array of separator characters, not a separator string. */ | |
847
7f41a4b33975
t_strsplit() returns now const char **, which removes a few nasty casts.
Timo Sirainen <tss@iki.fi>
parents:
839
diff
changeset
|
54 const char **t_strsplit(const char *data, const char *separators); |
0 | 55 |
807
35abd7a5d381
Buffer related cleanups. Use PATH_MAX instead of hardcoded 1024 for paths.
Timo Sirainen <tss@iki.fi>
parents:
678
diff
changeset
|
56 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
|
57 |
0 | 58 /* INTERNAL */ |
839
34cb1d196d2b
String function cleanups. Allocating 0 bytes of memory is treated as error
Timo Sirainen <tss@iki.fi>
parents:
833
diff
changeset
|
59 const char *_vstrconcat(const char *str1, va_list args, size_t *ret_len); |
0 | 60 |
61 #endif |