X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fpath-util.c;h=fc42a704b7fd77742da60639333e848452e90d6b;hp=fcacf541ed83970be11fc44b842ae380bcb1ed88;hb=4e2f8d27781731021aa6b96c0ee18a8966eefe1c;hpb=97f2d76d4f4dfab8b0629c09926a05a1e5621125 diff --git a/src/shared/path-util.c b/src/shared/path-util.c index fcacf541e..fc42a704b 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; @@ -428,6 +416,8 @@ int path_is_os_tree(const char *path) { int find_binary(const char *name, char **filename) { assert(name); + assert(filename); + if (strchr(name, '/')) { char *p; @@ -474,33 +464,37 @@ int find_binary(const char *name, char **filename) { } } -bool paths_check_timestamp(char **paths, usec_t *timestamp, bool update) -{ - unsigned int i; +bool paths_check_timestamp(const char* const* paths, usec_t *timestamp, bool update) { bool changed = false; + const char* const* i; assert(timestamp); if (paths == NULL) - goto out; + return false; - for (i = 0; paths[i]; i++) { + STRV_FOREACH(i, paths) { struct stat stats; + usec_t u; - if (stat(paths[i], &stats) < 0) + if (stat(*i, &stats) < 0) continue; + u = timespec_load(&stats.st_mtim); + /* first check */ - if (*timestamp >= timespec_load(&stats.st_mtim)) + if (*timestamp >= u) continue; - log_debug("timestamp of '%s' changed\n", paths[i]); - changed = true; + log_debug("timestamp of '%s' changed", *i); /* update timestamp */ - if (update) - *timestamp = timespec_load(&stats.st_mtim); + if (update) { + *timestamp = u; + changed = true; + } else + return true; } -out: + return changed; }