summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/path-util.c12
-rw-r--r--src/shared/path-util.h2
-rw-r--r--src/shared/util.c58
-rw-r--r--src/shared/util.h4
4 files changed, 15 insertions, 61 deletions
diff --git a/src/shared/path-util.c b/src/shared/path-util.c
index b51a68d6d2..70c8a8af06 100644
--- a/src/shared/path-util.c
+++ b/src/shared/path-util.c
@@ -264,12 +264,12 @@ char *path_kill_slashes(char *path) {
return path;
}
-bool path_startswith(const char *path, const char *prefix) {
+char* path_startswith(const char *path, const char *prefix) {
assert(path);
assert(prefix);
if ((path[0] == '/') != (prefix[0] == '/'))
- return false;
+ return NULL;
for (;;) {
size_t a, b;
@@ -278,19 +278,19 @@ bool path_startswith(const char *path, const char *prefix) {
prefix += strspn(prefix, "/");
if (*prefix == 0)
- return true;
+ return (char*) path;
if (*path == 0)
- return false;
+ return NULL;
a = strcspn(path, "/");
b = strcspn(prefix, "/");
if (a != b)
- return false;
+ return NULL;
if (memcmp(path, prefix, a) != 0)
- return false;
+ return NULL;
path += a;
prefix += b;
diff --git a/src/shared/path-util.h b/src/shared/path-util.h
index a441783b15..e81821a28f 100644
--- a/src/shared/path-util.h
+++ b/src/shared/path-util.h
@@ -32,7 +32,7 @@ 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);
-bool path_startswith(const char *path, const char *prefix);
+char *path_startswith(const char *path, const char *prefix);
bool path_equal(const char *a, const char *b);
char **path_strv_make_absolute_cwd(char **l);
diff --git a/src/shared/util.c b/src/shared/util.c
index 6a40cf1d80..add3fdce53 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4644,49 +4644,9 @@ int copy_file(const char *from, const char *to) {
return 0;
}
-int symlink_or_copy(const char *from, const char *to) {
- char *pf = NULL, *pt = NULL;
- struct stat a, b;
- int r;
-
- assert(from);
- assert(to);
-
- if (path_get_parent(from, &pf) < 0 ||
- path_get_parent(to, &pt) < 0) {
- r = -ENOMEM;
- goto finish;
- }
-
- if (stat(pf, &a) < 0 ||
- stat(pt, &b) < 0) {
- r = -errno;
- goto finish;
- }
-
- if (a.st_dev != b.st_dev) {
- free(pf);
- free(pt);
-
- return copy_file(from, to);
- }
-
- if (symlink(from, to) < 0) {
- r = -errno;
- goto finish;
- }
-
- r = 0;
-
-finish:
- free(pf);
- free(pt);
-
- return r;
-}
-
-int symlink_or_copy_atomic(const char *from, const char *to) {
- char *t, *x;
+int symlink_atomic(const char *from, const char *to) {
+ char *x;
+ _cleanup_free_ char *t;
const char *fn;
size_t k;
unsigned long long ull;
@@ -4714,22 +4674,16 @@ int symlink_or_copy_atomic(const char *from, const char *to) {
*x = 0;
- r = symlink_or_copy(from, t);
- if (r < 0) {
- unlink(t);
- free(t);
- return r;
- }
+ if (symlink(from, t) < 0)
+ return -errno;
if (rename(t, to) < 0) {
r = -errno;
unlink(t);
- free(t);
return r;
}
- free(t);
- return r;
+ return 0;
}
bool display_is_local(const char *display) {
diff --git a/src/shared/util.h b/src/shared/util.h
index a3f825b5bb..2b75ba62f9 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -430,8 +430,8 @@ int terminal_vhangup(const char *name);
int vt_disallocate(const char *name);
int copy_file(const char *from, const char *to);
-int symlink_or_copy(const char *from, const char *to);
-int symlink_or_copy_atomic(const char *from, const char *to);
+
+int symlink_atomic(const char *from, const char *to);
int fchmod_umask(int fd, mode_t mode);