File: util.h

package info (click to toggle)
fetchmail 6.6.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,888 kB
  • sloc: ansic: 19,454; sh: 7,111; python: 2,395; perl: 564; yacc: 447; lex: 286; makefile: 261; awk: 124; lisp: 84; exp: 43; sed: 17
file content (41 lines) | stat: -rw-r--r-- 1,600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** \file util.h - headers for utility functions
 * \author Matthias Andree
 * \copyright 2025. GPLv2+
 */

#ifndef FM_UTIL_H
#define FM_UTIL_H

#include <assert.h>
#include <stdbool.h>
#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/* util.c */
/** This function will use \ref strtok_r to thread-safely split the writable
 * string \a str (writing \0 characters into it)
 * according to any of the delimiter characters in the string \a delim,
 * place the resulting pointer into \a outarray
 * and extract at most \a maxsplit components. \a maxsplit must not be larger than the amount of character pointers in \a outarray.
 * If there are fewer delimiters in the input string, it will
 * write a NULL pointer into array. \returns number of splits, i. e. number of time strtok_r returned a pointer. May be 0 if delim isn't found.
 */
size_t str_split(char *str /** input string. Must not be NULL, and must be writable because strtok_r needs to embed \0 characters. */,
        const char *delim /** delimiters, passed to strtok_r verbatim */,
        char *outarray[] /** output array */,
        size_t maxsplit /** maximum number of components, must not be larger than number of elements in \a outarray */,
        char **remainder /** If non-NULL, copies the pointer to the remainder of the string to \a *remainder. */);

/** This function checks if \a str begins with \a prefix. \return true if it does. */
bool str_startswith(const char *str /** string to check for \a prefix */, 
        const char *prefix /** prefix of string to check */);


#ifdef __cplusplus
}
#endif

#endif