PatchworkOS
19e446b
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
argsplit.h
Go to the documentation of this file.
1
#ifndef _SYS_ARGSPLIT_H
2
#define _SYS_ARGSPLIT_H 1
3
4
#include <
stdint.h
>
5
6
#if defined(__cplusplus)
7
extern
"C"
8
{
9
#endif
10
11
#include "
_libstd/config.h
"
12
13
/**
14
* @brief Standardized argument parsing
15
* @ingroup libstd
16
* @defgroup libstd_sys_argsplit Argument parsing
17
*
18
* The `sys/argsplit.h` header provides a system for standardized argument parsing, allowing arguments to be parsed in
19
* the same way in various parts of the operating system.
20
*
21
* @{
22
*/
23
24
/**
25
* @brief Standardized argument parsing function.
26
*
27
* The `argsplit()` function parses a input string and splits it into a NULL-terminated array of strings factoring in
28
* escape chars spaces and quotation marks.
29
*
30
* The caller is responsible for freeing the returned array, there is no need to free the strings as they re stored in
31
* the same buffer.
32
*
33
* @param str The input string to be parsed.
34
* @param maxLen The maximum length of the input string.
35
* @param count A pointer to a `uint64_t` where the number of parsed arguments will be stored.
36
* @return On success, returns a `NULL`-terminated array of strings (the parsed arguments). On failure, returns `NULL`.
37
*/
38
const
char
**
argsplit
(
const
char
* str,
uint64_t
maxLen,
uint64_t
*
count
);
39
40
/**
41
* @brief Standardized argument parsing function using a provided buffer.
42
*
43
* The `argsplit_buf()` function is similar to `argsplit()` but uses a pre-allocated buffer for storing the parsed
44
* arguments, useful for memory management.
45
*
46
* @param buf A pointer to the buffer to be used for storing the parsed arguments.
47
* @param size The size of the provided buffer.
48
* @param str The input string to be parsed.
49
* @param maxLen The maximum length of the input string.
50
* @param count A pointer to a `uint64_t` where the number of parsed arguments will be stored.
51
* @return On success, returns a `NULL`-terminated array of strings (the parsed arguments) stored within the provided
52
* buffer. On failure, returns `NULL`.
53
*/
54
const
char
**
argsplit_buf
(
void
* buf,
uint64_t
size,
const
char
* str,
uint64_t
maxLen,
uint64_t
*
count
);
55
56
#if defined(__cplusplus)
57
}
58
#endif
59
60
#endif
61
62
/** @} */
config.h
argsplit_buf
const char ** argsplit_buf(void *buf, uint64_t size, const char *str, uint64_t maxLen, uint64_t *count)
Standardized argument parsing function using a provided buffer.
Definition
argsplit_buf.c:3
argsplit
const char ** argsplit(const char *str, uint64_t maxLen, uint64_t *count)
Standardized argument parsing function.
Definition
argsplit.c:3
count
static atomic_long count
Definition
main.c:11
stdint.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
include
sys
argsplit.h
Generated on Sat Jan 24 2026 10:59:24 for PatchworkOS by
1.9.8