summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libudev/path-util.c45
-rw-r--r--src/libudev/path-util.h30
2 files changed, 34 insertions, 41 deletions
diff --git a/src/libudev/path-util.c b/src/libudev/path-util.c
index 70c8a8af06..d7f21b3322 100644
--- a/src/libudev/path-util.c
+++ b/src/libudev/path-util.c
@@ -50,7 +50,8 @@ char *path_get_file_name(const char *p) {
assert(p);
- if ((r = strrchr(p, '/')))
+ r = strrchr(p, '/');
+ if (r)
return r + 1;
return (char*) p;
@@ -135,7 +136,8 @@ char *path_make_absolute_cwd(const char *p) {
if (path_is_absolute(p))
return strdup(p);
- if (!(cwd = get_current_dir_name()))
+ cwd = get_current_dir_name();
+ if (!cwd)
return NULL;
r = path_make_absolute(p, cwd);
@@ -181,6 +183,7 @@ char **path_strv_canonicalize(char **l) {
t = path_make_absolute_cwd(*s);
free(*s);
+ *s = NULL;
if (!t) {
enomem = true;
@@ -189,14 +192,18 @@ char **path_strv_canonicalize(char **l) {
errno = 0;
u = canonicalize_file_name(t);
- free(t);
-
if (!u) {
- if (errno == ENOMEM || !errno)
- enomem = true;
-
- continue;
- }
+ if (errno == ENOENT)
+ u = t;
+ else {
+ free(t);
+ if (errno == ENOMEM || !errno)
+ enomem = true;
+
+ continue;
+ }
+ } else
+ free(t);
l[k++] = u;
}
@@ -209,24 +216,14 @@ char **path_strv_canonicalize(char **l) {
return l;
}
-char **path_strv_remove_empty(char **l) {
- char **f, **t;
+char **path_strv_canonicalize_uniq(char **l) {
+ if (strv_isempty(l))
+ return l;
- if (!l)
+ if (!path_strv_canonicalize(l))
return NULL;
- for (f = t = l; *f; f++) {
-
- if (dir_is_empty(*f) > 0) {
- free(*f);
- continue;
- }
-
- *(t++) = *f;
- }
-
- *t = NULL;
- return l;
+ return strv_uniq(l);
}
char *path_kill_slashes(char *path) {
diff --git a/src/libudev/path-util.h b/src/libudev/path-util.h
index e81821a28f..348157fc10 100644
--- a/src/libudev/path-util.h
+++ b/src/libudev/path-util.h
@@ -1,7 +1,6 @@
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
-#ifndef foopathutilhfoo
-#define foopathutilhfoo
+#pragma once
/***
This file is part of systemd.
@@ -22,24 +21,21 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
-#include "stdbool.h"
+#include <stdbool.h>
-bool is_path(const char *p);
-char **path_split_and_make_absolute(const char *p);
-char *path_get_file_name(const char *p);
+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);
-char *path_make_absolute(const char *p, const char *prefix);
-char *path_make_absolute_cwd(const char *p);
-char *path_kill_slashes(char *path);
-char *path_startswith(const char *path, const char *prefix);
-bool path_equal(const char *a, const char *b);
+bool path_is_absolute(const char *p) _pure_;
+char* path_make_absolute(const char *p, const char *prefix);
+char* path_make_absolute_cwd(const char *p);
+char* path_kill_slashes(char *path);
+char* path_startswith(const char *path, const char *prefix) _pure_;
+bool path_equal(const char *a, const char *b) _pure_;
-char **path_strv_make_absolute_cwd(char **l);
-char **path_strv_canonicalize(char **l);
-char **path_strv_remove_empty(char **l);
+char** path_strv_make_absolute_cwd(char **l);
+char** path_strv_canonicalize(char **l);
int path_is_mount_point(const char *path, bool allow_symlink);
int path_is_read_only_fs(const char *path);
-
-#endif