#include <langinfo.h>
#include <locale.h>
#include <libgen.h>
+#undef basename
#include "macro.h"
#include "util.h"
if (!t)
return -ENOMEM;
- fn = path_get_file_name(path);
- k = fn-path;
+ fn = basename(path);
+ k = fn - path;
memcpy(t, path, k);
t[k] = '.';
stpcpy(stpcpy(t+k+1, fn), "XXXXXX");
if (!t)
return -ENOMEM;
- fn = path_get_file_name(to);
+ fn = basename(to);
k = fn-to;
memcpy(t, to, k);
t[k] = '.';
goto out;
}
- if(streq(set, "UTF-8")) {
+ if (streq(set, "UTF-8")) {
cached_answer = true;
goto out;
}
size_t a;
void *q;
+ assert(p);
assert(allocated);
if (*allocated >= need)
return *p;
a = MAX(64u, need * 2);
+
+ /* check for overflows */
+ if (a < need)
+ return NULL;
+
q = realloc(*p, a);
if (!q)
return NULL;
}
void* greedy_realloc0(void **p, size_t *allocated, size_t need) {
- size_t prev = *allocated;
+ size_t prev;
uint8_t *q;
+ assert(p);
+ assert(allocated);
+
+ prev = *allocated;
+
q = greedy_realloc(p, allocated, need);
if (!q)
return NULL;
return 1;
FOREACH_WORD_QUOTED(w, l, line, state)
- if (l == 23 && memcmp(w, "systemd.restore_state=0", 23))
+ if (l == 23 && strneq(w, "systemd.restore_state=0", 23))
return 0;
return 1;