/src/systemd/src/basic/env-util.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
2 | | #pragma once |
3 | | |
4 | | #include <stdbool.h> |
5 | | #include <stddef.h> |
6 | | #include <stdio.h> |
7 | | #include <unistd.h> |
8 | | |
9 | | #include "macro.h" |
10 | | #include "string.h" |
11 | | |
12 | 0 | static inline size_t sc_arg_max(void) { |
13 | 0 | long l = sysconf(_SC_ARG_MAX); |
14 | 0 | assert(l > 0); |
15 | 0 | return (size_t) l; |
16 | 0 | } |
17 | | |
18 | | bool env_name_is_valid(const char *e); |
19 | | bool env_value_is_valid(const char *e); |
20 | | bool env_assignment_is_valid(const char *e); |
21 | | |
22 | | enum { |
23 | | REPLACE_ENV_USE_ENVIRONMENT = 1 << 0, |
24 | | REPLACE_ENV_ALLOW_BRACELESS = 1 << 1, |
25 | | REPLACE_ENV_ALLOW_EXTENDED = 1 << 2, |
26 | | }; |
27 | | |
28 | | char *replace_env_n(const char *format, size_t n, char **env, unsigned flags); |
29 | | char **replace_env_argv(char **argv, char **env); |
30 | | |
31 | 0 | static inline char *replace_env(const char *format, char **env, unsigned flags) { |
32 | 0 | return replace_env_n(format, strlen(format), env, flags); |
33 | 0 | } |
34 | | |
35 | | bool strv_env_is_valid(char **e); |
36 | | #define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL) |
37 | | char **strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata); |
38 | | |
39 | | bool strv_env_name_is_valid(char **l); |
40 | | bool strv_env_name_or_assignment_is_valid(char **l); |
41 | | |
42 | | char** _strv_env_merge(char **first, ...); |
43 | | #define strv_env_merge(first, ...) _strv_env_merge(first, __VA_ARGS__, POINTER_MAX) |
44 | | char **strv_env_delete(char **x, size_t n_lists, ...); /* New copy */ |
45 | | |
46 | | char **strv_env_unset(char **l, const char *p); /* In place ... */ |
47 | | char **strv_env_unset_many(char **l, ...) _sentinel_; |
48 | | int strv_env_replace_consume(char ***l, char *p); /* In place ... */ |
49 | | int strv_env_replace_strdup(char ***l, const char *assignment); |
50 | | int strv_env_replace_strdup_passthrough(char ***l, const char *assignment); |
51 | | int strv_env_assign(char ***l, const char *key, const char *value); |
52 | | |
53 | | char *strv_env_get_n(char **l, const char *name, size_t k, unsigned flags) _pure_; |
54 | | char *strv_env_get(char **x, const char *n) _pure_; |
55 | | char *strv_env_pairs_get(char **l, const char *name) _pure_; |
56 | | |
57 | | int getenv_bool(const char *p); |
58 | | int getenv_bool_secure(const char *p); |
59 | | |
60 | | int getenv_uint64_secure(const char *p, uint64_t *ret); |
61 | | |
62 | | /* Like setenv, but calls unsetenv if value == NULL. */ |
63 | | int set_unset_env(const char *name, const char *value, bool overwrite); |
64 | | |
65 | | /* Like putenv, but duplicates the memory like setenv. */ |
66 | | int putenv_dup(const char *assignment, bool override); |
67 | | |
68 | | int setenv_systemd_exec_pid(bool update_only); |
69 | | |
70 | | /* Parses and does sanity checks on an environment variable containing |
71 | | * PATH-like colon-separated absolute paths */ |
72 | | int getenv_path_list(const char *name, char ***ret_paths); |
73 | | |
74 | | int getenv_steal_erase(const char *name, char **ret); |