diff options
author | Anthony G. Basile <blueness@gentoo.org> | 2013-06-04 07:20:01 -0400 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2013-06-04 08:02:34 -0400 |
commit | 00e01c3841eb1ab67ab4d358731740ae836c64b8 (patch) | |
tree | 0e1b5a02720768c8aff3e148f74ed79fd941b03d | |
parent | 1cc8667cd93d764db6689820825eb78746060384 (diff) |
src/libudev/path-util.c: bring in line with upstream
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r-- | src/libudev/path-util.c | 45 | ||||
-rw-r--r-- | src/libudev/path-util.h | 30 |
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 |