summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-06 21:29:55 -0500
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-12-06 21:29:55 -0500
commit2b6bf07dd23bb467099d213c97b3875c5e453491 (patch)
tree2127e24f28714b48f6c00e92eaec351bcb57e5d5 /src/shared
parentf4336098941f94d23f2f6c79bc8d055a0907c392 (diff)
Get rid of our reimplementation of basename
The only problem is that libgen.h #defines basename to point to it's own broken implementation instead of the GNU one. This can be fixed by #undefining basename.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/cgroup-show.c4
-rw-r--r--src/shared/conf-files.c4
-rw-r--r--src/shared/install.c16
-rw-r--r--src/shared/path-util.c12
-rw-r--r--src/shared/path-util.h1
-rw-r--r--src/shared/util.c7
-rw-r--r--src/shared/utmp-wtmp.c2
7 files changed, 17 insertions, 29 deletions
diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c
index ce02b76e36..ee14cee4ed 100644
--- a/src/shared/cgroup-show.c
+++ b/src/shared/cgroup-show.c
@@ -178,7 +178,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
if (last) {
printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_BRANCH),
- path_get_file_name(last));
+ basename(last));
if (!p1) {
p1 = strappend(prefix, draw_special_char(DRAW_TREE_VERT));
@@ -202,7 +202,7 @@ int show_cgroup_by_path(const char *path, const char *prefix, unsigned n_columns
if (last) {
printf("%s%s%s\n", prefix, draw_special_char(DRAW_TREE_RIGHT),
- path_get_file_name(last));
+ basename(last));
if (!p2) {
p2 = strappend(prefix, " ");
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index ed4070c662..92204a6a09 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -71,7 +71,7 @@ static int files_add(Hashmap *h, const char *root, const char *path, const char
if (!p)
return -ENOMEM;
- r = hashmap_put(h, path_get_file_name(p), p);
+ r = hashmap_put(h, basename(p), p);
if (r == -EEXIST) {
log_debug("Skipping overridden file: %s.", p);
free(p);
@@ -92,7 +92,7 @@ static int base_cmp(const void *a, const void *b) {
s1 = *(char * const *)a;
s2 = *(char * const *)b;
- return strcmp(path_get_file_name(s1), path_get_file_name(s2));
+ return strcmp(basename(s1), basename(s2));
}
static int conf_files_list_strv_internal(char ***strv, const char *suffix, const char *root, char **dirs) {
diff --git a/src/shared/install.c b/src/shared/install.c
index 100ed69744..17e8a7508e 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -276,10 +276,10 @@ static int remove_marked_symlinks_fd(
found =
set_get(remove_symlinks_to, dest) ||
- set_get(remove_symlinks_to, path_get_file_name(dest));
+ set_get(remove_symlinks_to, basename(dest));
if (unit_name_is_instance(p))
- found = found && strv_contains(files, path_get_file_name(p));
+ found = found && strv_contains(files, basename(p));
if (found) {
@@ -451,7 +451,7 @@ static int find_symlinks_fd(
if (path_is_absolute(name))
found_dest = path_equal(dest, name);
else
- found_dest = streq(path_get_file_name(dest), name);
+ found_dest = streq(basename(dest), name);
if (found_path && found_dest) {
_cleanup_free_ char *t = NULL;
@@ -718,7 +718,7 @@ int unit_file_link(
char *fn;
struct stat st;
- fn = path_get_file_name(*i);
+ fn = basename(*i);
if (!path_is_absolute(*i) ||
!unit_name_is_valid(fn, true)) {
@@ -861,7 +861,7 @@ static int install_info_add(
assert(name || path);
if (!name)
- name = path_get_file_name(path);
+ name = basename(path);
if (!unit_name_is_valid(name, true))
return -EINVAL;
@@ -1429,7 +1429,7 @@ static int install_context_mark_for_removal(
char *unit_file;
if (i->path) {
- unit_file = path_get_file_name(i->path);
+ unit_file = basename(i->path);
if (unit_name_is_instance(unit_file))
/* unit file named as instance exists, thus all symlinks
@@ -1647,7 +1647,7 @@ int unit_file_get_default(
else if (r < 0)
return r;
else
- n = strdup(path_get_file_name(tmp));
+ n = strdup(basename(tmp));
if (!n)
return -ENOMEM;
@@ -2007,7 +2007,7 @@ int unit_file_get_list(
f->state = UNIT_FILE_STATIC;
found:
- r = hashmap_put(h, path_get_file_name(f->path), f);
+ r = hashmap_put(h, basename(f->path), f);
if (r < 0)
return r;
f = NULL; /* prevent cleanup */
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index 6c4efbfd94..3843861779 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -45,18 +45,6 @@ bool is_path(const char *p) {
return !!strchr(p, '/');
}
-char *path_get_file_name(const char *p) {
- char *r;
-
- assert(p);
-
- r = strrchr(p, '/');
- if (r)
- return r + 1;
-
- return (char*) p;
-}
-
int path_get_parent(const char *path, char **_r) {
const char *e, *a = NULL, *b = NULL, *p;
char *r;
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
index 42b4189d77..1098f6540c 100644
--- a/src/shared/path-util.h
+++ b/src/shared/path-util.h
@@ -34,7 +34,6 @@
bool is_path(const char *p) _pure_;
char** path_split_and_make_absolute(const char *p);
-char* path_get_file_name(const char *p) _pure_;
int path_get_parent(const char *path, char **parent);
bool path_is_absolute(const char *p) _pure_;
char* path_make_absolute(const char *p, const char *prefix);
diff --git a/src/shared/util.c b/src/shared/util.c
index c71293106f..9c07392c59 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -59,6 +59,7 @@
#include <langinfo.h>
#include <locale.h>
#include <libgen.h>
+#undef basename
#include "macro.h"
#include "util.h"
@@ -3961,8 +3962,8 @@ int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
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");
@@ -4147,7 +4148,7 @@ int symlink_atomic(const char *from, const char *to) {
if (!t)
return -ENOMEM;
- fn = path_get_file_name(to);
+ fn = basename(to);
k = fn-to;
memcpy(t, to, k);
t[k] = '.';
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 5d88405e13..4a3a3f4dd3 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -216,7 +216,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
strncpy(store.ut_id, sanitize_id(id), sizeof(store.ut_id));
if (line)
- strncpy(store.ut_line, path_get_file_name(line), sizeof(store.ut_line));
+ strncpy(store.ut_line, basename(line), sizeof(store.ut_line));
return write_entry_both(&store);
}