summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-28 20:17:24 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-28 23:45:59 -0400
commit844ec79b3c2f246114ea316ebe1f36044bdb688e (patch)
tree6e937c3738ee75fdd2c22e5f9bec72d789d6e13b /src/shared/util.c
parent18cd5fe99f70a55a2d6f2303d6ee0624942695b1 (diff)
catalog: open up catalog internals
In order to write tests for the catalog functions, they are made non-static and start taking a 'database' parameter, which is the name of a file with the preprocessed catalog entries. This makes it possible to make test-catalog part of the normal test suite, since it now only operates on files in /tmp. Some more tests are added.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 8fa01fa8a4..2241b79859 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -59,6 +59,7 @@
#include <limits.h>
#include <langinfo.h>
#include <locale.h>
+#include <libgen.h>
#include "macro.h"
#include "util.h"
@@ -2356,6 +2357,24 @@ int dir_is_empty(const char *path) {
}
}
+char* dirname_malloc(const char *path) {
+ char *d, *dir, *dir2;
+
+ d = strdup(path);
+ if (!d)
+ return NULL;
+ dir = dirname(d);
+ assert(dir);
+
+ if (dir != d) {
+ dir2 = strdup(dir);
+ free(d);
+ return dir2;
+ }
+
+ return dir;
+}
+
unsigned long long random_ull(void) {
_cleanup_close_ int fd;
uint64_t ull;