X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Futil.c;h=85a8e37d4b559aca10af667fbd6f101c577e99b4;hp=47b1b443ff46783a46398e98cdf97649a375c667;hb=1b91d3e8f402829f336daa5f768e768aede373da;hpb=9a34ec5fbb4b55413dc9d610b636fe760d34ecd7 diff --git a/src/util.c b/src/util.c index 47b1b443f..85a8e37d4 100644 --- a/src/util.c +++ b/src/util.c @@ -652,6 +652,51 @@ char **strv_path_make_absolute_cwd(char **l) { return l; } +char **strv_path_canonicalize(char **l) { + char **s; + unsigned k = 0; + bool enomem = false; + + if (strv_isempty(l)) + return l; + + /* Goes through every item in the string list and canonicalize + * the path. This works in place and won't rollback any + * changes on failure. */ + + STRV_FOREACH(s, l) { + char *t, *u; + + t = path_make_absolute_cwd(*s); + free(*s); + + if (!t) { + enomem = true; + continue; + } + + errno = 0; + u = canonicalize_file_name(t); + free(t); + + if (!u) { + if (errno == ENOMEM || !errno) + enomem = true; + + continue; + } + + l[k++] = u; + } + + l[k] = NULL; + + if (enomem) + return NULL; + + return l; +} + int reset_all_signal_handlers(void) { int sig;