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