if (n == SIZE_MAX)
n = strlen_ptr(e);
- if (n <= 0)
+ if (n == 0)
return false;
assert(e);
/* POSIX says the overall size of the environment block cannot be > ARG_MAX, an individual assignment
* hence cannot be either. Discounting the equal sign and trailing NUL this hence leaves ARG_MAX-2 as
* longest possible variable name. */
- if (n > (size_t) sysconf(_SC_ARG_MAX) - 2)
+ if (_unlikely_(n > sc_arg_max() - 2))
return false;
for (const char *p = e; p < e + n; p++)
}
bool env_name_is_valid(const char *e) {
- return env_name_is_valid_n(e, strlen_ptr(e));
+ return env_name_is_valid_n(e, SIZE_MAX);
}
bool env_value_is_valid(const char *e) {
/* POSIX says the overall size of the environment block cannot be > ARG_MAX, an individual assignment
* hence cannot be either. Discounting the shortest possible variable name of length 1, the equal
* sign and trailing NUL this hence leaves ARG_MAX-3 as longest possible variable value. */
- if (strlen(e) > sc_arg_max() - 3)
+ if (_unlikely_(strlen(e) > sc_arg_max() - 3))
return false;
return true;
bool env_assignment_is_valid(const char *e) {
const char *eq;
+ assert(e);
+
eq = strchr(e, '=');
if (!eq)
return false;
/* POSIX says the overall size of the environment block cannot be > ARG_MAX, hence the individual
* variable assignments cannot be either, but let's leave room for one trailing NUL byte. */
- if (strlen(e) > sc_arg_max() - 1)
+ if (_unlikely_(strlen(e) > sc_arg_max() - 1))
return false;
return true;
}
-bool strv_env_is_valid(char **e) {
+bool strv_env_is_valid(char * const *e) {
STRV_FOREACH(p, e) {
size_t k;
return true;
}
-bool strv_env_name_is_valid(char **l) {
+bool strv_env_name_is_valid(char * const *l) {
STRV_FOREACH(p, l) {
if (!env_name_is_valid(*p))
return false;
return true;
}
-bool strv_env_name_or_assignment_is_valid(char **l) {
+bool strv_env_name_or_assignment_is_valid(char * const *l) {
STRV_FOREACH(p, l) {
if (!env_assignment_is_valid(*p) && !env_name_is_valid(*p))
return false;
int replace_env_argv(char **argv, char **env, char ***ret, char ***ret_unset_variables, char ***ret_bad_variables);
-bool strv_env_is_valid(char **e);
-#define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL)
-char** strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata);
+bool strv_env_is_valid(char * const *e);
+bool strv_env_name_is_valid(char * const *l);
+bool strv_env_name_or_assignment_is_valid(char * const *l);
-bool strv_env_name_is_valid(char **l);
-bool strv_env_name_or_assignment_is_valid(char **l);
+char** strv_env_clean_with_callback(char **l, void (*invalid_callback)(const char *p, void *userdata), void *userdata);
+#define strv_env_clean(l) strv_env_clean_with_callback(l, NULL, NULL)
char** _strv_env_merge(char **first, ...);
#define strv_env_merge(first, ...) _strv_env_merge(first, __VA_ARGS__, POINTER_MAX)