tree-wide: replace string functions with fundamental functions
This commit is contained in:
@@ -244,9 +244,9 @@ static bool env_match(const char *t, const char *pattern) {
|
||||
return true;
|
||||
|
||||
if (!strchr(pattern, '=')) {
|
||||
size_t l = strlen(pattern);
|
||||
t = startswith(t, pattern);
|
||||
|
||||
return strneq(t, pattern, l) && t[l] == '=';
|
||||
return t && *t == '=';
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -1024,7 +1024,7 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
char *value = NULL;
|
||||
const char *path;
|
||||
size_t l, sum = 0;
|
||||
size_t sum = 0;
|
||||
int r;
|
||||
|
||||
assert(pid >= 0);
|
||||
@@ -1059,9 +1059,9 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
l = strlen(field);
|
||||
for (;;) {
|
||||
_cleanup_free_ char *line = NULL;
|
||||
const char *match;
|
||||
|
||||
if (sum > ENVIRONMENT_BLOCK_MAX) /* Give up searching eventually */
|
||||
return -ENOBUFS;
|
||||
@@ -1074,8 +1074,9 @@ int getenv_for_pid(pid_t pid, const char *field, char **ret) {
|
||||
|
||||
sum += r;
|
||||
|
||||
if (strneq(line, field, l) && line[l] == '=') {
|
||||
value = strdup(line + l + 1);
|
||||
match = startswith(line, field);
|
||||
if (match && *match == '=') {
|
||||
value = strdup(match + 1);
|
||||
if (!value)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
+7
-11
@@ -1509,24 +1509,20 @@ ssize_t strlevenshtein(const char *x, const char *y) {
|
||||
}
|
||||
|
||||
char *strrstr(const char *haystack, const char *needle) {
|
||||
const char *f = NULL;
|
||||
size_t l;
|
||||
|
||||
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
|
||||
|
||||
if (!haystack || !needle)
|
||||
return NULL;
|
||||
|
||||
l = strlen(needle);
|
||||
|
||||
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
|
||||
* last char, not before. */
|
||||
if (l == 0)
|
||||
if (*needle == 0)
|
||||
return strchr(haystack, 0);
|
||||
|
||||
for (const char *p = haystack; *p; p++)
|
||||
if (strneq(p, needle, l))
|
||||
f = p;
|
||||
|
||||
return (char*) f;
|
||||
for (const char *p = strstr(haystack, needle), *q; p; p = q) {
|
||||
q = strstr(p + 1, needle);
|
||||
if (!q)
|
||||
return (char *) p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user