summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libsystem/config-parser.c10
-rw-r--r--src/libsystem/libsystem.c44
-rw-r--r--src/libsystem/proc.c18
3 files changed, 31 insertions, 41 deletions
diff --git a/src/libsystem/config-parser.c b/src/libsystem/config-parser.c
index e6ade0e..2799f0a 100644
--- a/src/libsystem/config-parser.c
+++ b/src/libsystem/config-parser.c
@@ -103,9 +103,7 @@ static int config_parse_table(
return 0;
}
-int config_parse(
- const char *filename,
- void *table) {
+int config_parse(const char *filename, void *table) {
_cleanup_fclose_ FILE *f = NULL;
char *sections[MAX_SECTION] = { 0 };
@@ -140,12 +138,12 @@ int config_parse(
if (*l == '[') {
len = strlen(l);
- if (l[len-1] != ']') {
+ if (l[len - 1] != ']') {
r = -EBADMSG;
goto finish;
}
- n = strndup(l+1, len-2);
+ n = strndup(l + 1, len - 2);
if (!n) {
r = -ENOMEM;
goto finish;
@@ -203,7 +201,7 @@ int config_parse(
r = 0;
finish:
- for (i=0; i<num_section; i++)
+ for (i = 0; i < num_section; i++)
if (sections[i])
free(sections[i]);
diff --git a/src/libsystem/libsystem.c b/src/libsystem/libsystem.c
index fb4a222..6f87eef 100644
--- a/src/libsystem/libsystem.c
+++ b/src/libsystem/libsystem.c
@@ -83,16 +83,16 @@ char *strnappend(const char *s, const char *suffix, size_t b) {
assert(suffix);
a = strlen(s);
- if (b > ((size_t) -1) - a)
+ if (b > ((size_t) - 1) - a)
return NULL;
- r = new(char, a+b+1);
+ r = new(char, a + b + 1);
if (!r)
return NULL;
memcpy(r, s, a);
- memcpy(r+a, suffix, b);
- r[a+b] = 0;
+ memcpy(r + a, suffix, b);
+ r[a + b] = 0;
return r;
}
@@ -109,7 +109,7 @@ char *strstrip(char *s) {
s += strspn(s, WHITESPACE);
- for (e = strchr(s, 0); e > s; e --)
+ for (e = strchr(s, 0); e > s; e--)
if (!strchr(WHITESPACE, e[-1]))
break;
@@ -168,7 +168,7 @@ int strndup_strip(const char *str, size_t len, char **ret) {
return 0;
}
-bool nulstr_contains(const char*nulstr, const char *needle) {
+bool nulstr_contains(const char *nulstr, const char *needle) {
const char *i;
if (!nulstr)
@@ -223,7 +223,7 @@ char *path_kill_slashes(char *path) {
return path;
}
-char* endswith(const char *s, const char *postfix) {
+char *endswith(const char *s, const char *postfix) {
size_t sl, pl;
assert(s);
@@ -233,7 +233,7 @@ char* endswith(const char *s, const char *postfix) {
pl = strlen(postfix);
if (pl == 0)
- return (char*) s + sl;
+ return (char *) s + sl;
if (sl < pl)
return NULL;
@@ -241,7 +241,7 @@ char* endswith(const char *s, const char *postfix) {
if (memcmp(s + sl - pl, postfix, pl) != 0)
return NULL;
- return (char*) s + sl - pl;
+ return (char *) s + sl - pl;
}
int parse_boolean(const char *v) {
@@ -267,7 +267,7 @@ int parse_bytes(const char *b, size_t *s) {
return 0;
num_l = strspn(b, "0123456789");
- if (num_l < len-1)
+ if (num_l < len - 1)
return -EINVAL;
unit_l = strcspn(b, "BKMG");
@@ -308,11 +308,11 @@ int parse_percent(const char *string, size_t *percent) {
if (!len)
return 0;
- if (string[len-1] != '%')
+ if (string[len - 1] != '%')
return -EINVAL;
num_len = strspn(string, "0123456789");
- if (num_len < len-1)
+ if (num_len < len - 1)
return -EINVAL;
num = strndup(string, num_len);
@@ -378,7 +378,7 @@ char *split(const char *c, size_t *l, const char *separator, char **state) {
assert(separator);
assert(state);
- current = *state ? *state : (char*) c;
+ current = *state ? *state : (char *) c;
if (!*current || *c == 0)
return NULL;
@@ -386,7 +386,7 @@ char *split(const char *c, size_t *l, const char *separator, char **state) {
separator_include_quotes = !!strspn(separator, QUOTES);
current += strspn(current, separator);
- while((s = strcspn(current + *l, separator))) {
+ while ((s = strcspn(current + *l, separator))) {
*l += s;
if (separator_include_quotes ||
quote_complete(current, *l))
@@ -396,7 +396,7 @@ char *split(const char *c, size_t *l, const char *separator, char **state) {
*state = current + *l;
- return (char *)current;
+ return (char *) current;
}
bool is_number(const char *s, int l) {
@@ -545,9 +545,8 @@ char *strdup_unquote(const char *str, const char *quotes) {
if (l < 2)
return strdup(str);
- if (strchr(quotes, str[0]) &&
- str[0] == str[l-1])
- return strndup(str+1, l-2);
+ if (strchr(quotes, str[0]) && str[0] == str[l - 1])
+ return strndup(str + 1, l - 2);
return strdup(str);
}
@@ -561,8 +560,7 @@ int write_str_to_file(FILE *f, const char *str, enum file_write_flags flags) {
STORE_RESET_ERRNO;
(void) fputs(str, f);
- if ((flags & FILE_WRITE_NEWLINE_IF_NOT) &&
- !endswith(str, "\n"))
+ if ((flags & FILE_WRITE_NEWLINE_IF_NOT) && !endswith(str, "\n"))
(void) fputc('\n', f);
if (flags & FILE_WRITE_WITH_FFLUSH)
@@ -918,7 +916,7 @@ int str_to_strv(const char *str, char ***strv, const char *separator) {
return -ENOMEM;
}
- new = (char **)realloc(v, sizeof(char *) * (i + 2));
+ new = (char **) realloc(v, sizeof(char *) * (i + 2));
if (!new) {
free(p);
free(v);
@@ -929,7 +927,7 @@ int str_to_strv(const char *str, char ***strv, const char *separator) {
v = new;
v[i] = p;
- v[i+1] = NULL;
+ v[i + 1] = NULL;
i++;
}
@@ -962,7 +960,7 @@ int strv_attach(char **first, char **second, char ***strv, bool free_second) {
if (second) {
n2 = sizeof_strv(second);
- new = (char **)realloc(first, sizeof(char *) * (n1 + n2 + 1));
+ new = (char **) realloc(first, sizeof(char *) * (n1 + n2 + 1));
if (!new)
return -ENOMEM;
diff --git a/src/libsystem/proc.c b/src/libsystem/proc.c
index 6a3d3df..49ddfde 100644
--- a/src/libsystem/proc.c
+++ b/src/libsystem/proc.c
@@ -89,7 +89,7 @@ int proc_pid_of(const char *pname) {
if (r < 0)
continue;
- if (strneq(pname, comm, TASK_COMM_LEN-1))
+ if (strneq(pname, comm, TASK_COMM_LEN - 1))
return atoi(de->d_name);
}
@@ -130,9 +130,7 @@ static int add_smap_to_smaps(struct smaps *maps, struct smap *map) {
maps->n_map++;
- maps->maps = (struct smap **)realloc(
- maps->maps,
- sizeof(struct smap *) * maps->n_map);
+ maps->maps = (struct smap **) realloc(maps->maps, sizeof(struct smap *) * maps->n_map);
if (!maps->maps)
return -ENOMEM;
@@ -189,8 +187,7 @@ int proc_pid_get_smaps(pid_t pid, struct smaps **maps, enum smap_mask mask) {
goto on_error;
}
- n = sscanf(buf, "%x-%x %ms %*s %*s %*s %ms",
- &map->start, &map->end, &map->mode, &map->name);
+ n = sscanf(buf, "%x-%x %ms %*s %*s %*s %ms", &map->start, &map->end, &map->mode, &map->name);
if (n == 3 && !map->name)
map->name = strdup("[anon]");
@@ -214,8 +211,7 @@ int proc_pid_get_smaps(pid_t pid, struct smaps **maps, enum smap_mask mask) {
break;
}
- if ((*buf >= '0' && *buf <= '9') ||
- (*buf >= 'a' && *buf <= 'f')) {
+ if ((*buf >= '0' && *buf <= '9') || (*buf >= 'a' && *buf <= 'f')) {
get_line = false;
break;
}
@@ -314,8 +310,7 @@ int proc_get_meminfo(struct meminfo *mi, enum meminfo_mask mask) {
return -errno;
if (remain_mask & MEMINFO_MASK_MEM_AVAILABLE)
- remain_mask |= (MEMINFO_MASK_MEM_FREE |
- MEMINFO_MASK_CACHED);
+ remain_mask |= (MEMINFO_MASK_MEM_FREE | MEMINFO_MASK_CACHED);
while (remain_mask) {
unsigned int v = 0;
@@ -350,8 +345,7 @@ int proc_get_meminfo(struct meminfo *mi, enum meminfo_mask mask) {
}
if (remain_mask & MEMINFO_MASK_MEM_AVAILABLE) {
- mi->value[MEMINFO_ID_MEM_AVAILABLE] =
- mi->value[MEMINFO_ID_MEM_FREE]
+ mi->value[MEMINFO_ID_MEM_AVAILABLE] = mi->value[MEMINFO_ID_MEM_FREE]
+ mi->value[MEMINFO_ID_CACHED];
}