1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-28 18:39:03 +00:00

Refactor user dir retrieval.

This commit is contained in:
david
2011-12-19 05:16:27 +00:00
parent 8cd4763fe1
commit 4766bae3ae

View File

@@ -240,37 +240,27 @@ static char *path_join(const char *first, ...)
return result;
}
static char *get_install_dir(void) {
struct passwd *pw;
static char *get_user_dir(const char *subdir) {
static struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
if (pw == NULL)
return NULL;
return path_join(pw->pw_dir, ".nmap", "updates", NULL);
return path_join(pw->pw_dir, ".nmap", subdir, NULL);
}
static char *get_install_dir(void) {
return get_user_dir("updates");
}
static char *get_staging_dir(void) {
struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
if (pw == NULL)
return NULL;
return path_join(pw->pw_dir, ".nmap", "updates-staging", NULL);
return get_user_dir("updates-staging");
}
static char *get_conf_filename(void) {
struct passwd *pw;
errno = 0;
pw = getpwuid(getuid());
if (pw == NULL)
return NULL;
return path_join(pw->pw_dir, ".nmap", "nmap-update.conf", NULL);
return get_user_dir("nmap-update.conf");
}