static int print_home(const char *n) { uint64_t i = 0; int r; for (i = 0; i < ELEMENTSOF(path_table); i++) { if (streq(path_table[i], n)) { _cleanup_free_ char *p = NULL; r = sd_path_home(i, arg_suffix, &p); if (r < 0) return log_error_errno(r, "Failed to query %s: %m", n); printf("%s\n", p); return 0; } } log_error("Path %s not known.", n); return -EOPNOTSUPP; }
static int environment_dirs(char ***ret) { _cleanup_strv_free_ char **dirs = NULL; _cleanup_free_ char *c = NULL; int r; dirs = strv_split_nulstr(CONF_PATHS_NULSTR("environment.d")); if (!dirs) return -ENOMEM; /* ~/.config/systemd/environment.d */ r = sd_path_home(SD_PATH_USER_CONFIGURATION, "environment.d", &c); if (r < 0) return r; r = strv_extend_front(&dirs, c); if (r < 0) return r; *ret = TAKE_PTR(dirs); return 0; }
static int list_homes(void) { uint64_t i = 0; int r = 0; for (i = 0; i < ELEMENTSOF(path_table); i++) { _cleanup_free_ char *p = NULL; int q; q = sd_path_home(i, arg_suffix, &p); if (q == -ENXIO) continue; if (q < 0) { log_error("Failed to query %s: %s", path_table[i], strerror(-r)); r = q; continue; } printf("%s: %s\n", path_table[i], p); } return r; }