manual: Bump required gcc version to 4.1.
[paraslash.git] / string.h
1 /*
2  * Copyright (C) 2006 Andre Noll <maan@tuebingen.mpg.de>
3  *
4  * Licensed under the GPL v2. For licencing details see COPYING.
5  */
6
7 /** \file string.h exported symbols from string.c */
8
9 /** Flags that change how content is printed into the buffer. */
10 enum para_buffer_flags {
11         /** Prefix each buffer with its length. */
12         PBF_SIZE_PREFIX = 1,
13 };
14
15 /** A string buffer used for para_printf(). */
16 struct para_buffer {
17         /** The buffer. May be \p NULL. */
18         char *buf;
19         /** The size of \a buf. */
20         size_t size;
21         /** The maximal size this buffer may grow. Zero means unlimited. */
22         size_t max_size;
23         /** \sa para_buffer_flags. */
24         unsigned flags;
25         /** The next para_printf() will write at this offset. */
26         size_t offset;
27         /**
28          * If an attempt to print into this buffer is made that would need to
29          * grow \a buf to a size larger than \a max_size, then this function is
30          * called.
31          */
32         int (*max_size_handler)(char *buf, size_t size, void *private_data);
33         /** Passed to max_size_handler(). */
34         void *private_data;
35 };
36
37 /**
38  * Controls the behavior of for_each_line().
39  *
40  * \sa for_each_line().
41  */
42 enum for_each_line_flags {
43         /** Activate read-only mode. */
44         FELF_READ_ONLY = 1 << 0,
45         /** Don't call line handler for the first input line. */
46         FELF_DISCARD_FIRST = 1 << 1,
47 };
48
49 /** Used for \ref for_each_line(). */
50 typedef int line_handler_t(char *, void *);
51 int for_each_line(unsigned flags, char *buf, size_t size,
52                 line_handler_t *line_handler, void *private_data);
53
54 /**
55   * Write the contents of a status item to a para_buffer.
56   *
57   * \param b The para_buffer.
58   * \param n The number of the status item.
59   * \param f A format string.
60   *
61   * \return The return value of the underlying call to para_printf().
62   */
63 #define WRITE_STATUS_ITEM(b, n, f, ...) (\
64 { \
65         if ((b)->flags & PBF_SIZE_PREFIX) { \
66                 para_printf((b), "%02x:" f, n, ## __VA_ARGS__); \
67         } else { \
68                 para_printf((b), "%s: " f, status_item_list[(n)], \
69                         ## __VA_ARGS__); \
70         } \
71 } \
72 )
73
74 __must_check __malloc void *para_realloc(void *p, size_t size);
75 __must_check __malloc void *para_malloc(size_t size);
76 __must_check __malloc void *para_calloc(size_t size);
77 __must_check __malloc char *para_strdup(const char *s);
78
79 __printf_2_0 unsigned xvasprintf(char **result, const char *fmt, va_list ap);
80 __printf_2_3 unsigned xasprintf(char **result, const char *fmt, ...);
81 __must_check __malloc __printf_1_2 char *make_message(const char *fmt, ...);
82 __must_check __malloc char *para_strcat(char *a, const char *b);
83 __must_check __malloc char *para_dirname(const char *name);
84 __must_check char *para_basename(const char *name);
85 __must_check __malloc char *para_logname(void);
86 __must_check __malloc char *para_homedir(void);
87 __malloc char *para_hostname(void);
88 __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...);
89 int para_atoi64(const char *str, int64_t *result);
90 int para_atoi32(const char *str, int32_t *value);
91 int get_loglevel_by_name(const char *txt);
92 int read_size_header(const char *buf);
93 int create_argv(const char *buf, const char *delim, char ***result);
94 int create_shifted_argv(const char *buf, const char *delim, char ***result);
95 int find_arg(const char *arg, char **argv);
96 void free_argv(char **argv);
97 int para_regcomp(regex_t *preg, const char *regex, int cflags);
98 void freep(void *arg);
99 int compute_word_num(const char *buf, const char *delim, int offset);
100 char *safe_strdup(const char *src, size_t len);
101 char *key_value_copy(const char *src, size_t len, const char *key);
102 int skip_cells(const char *s, size_t cells_to_skip, size_t *result);
103 __must_check int strwidth(const char *s, size_t *result);