From e51f1293aaa18359867db3a8de77b811f0933541 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Tue, 31 May 2022 00:38:37 +0000 Subject: [PATCH] Fix admin profile config and support APPDATA. Only use ALLUSERPROFILE for home dir when USERPROFILE is not set, even for admin users. Fix #34. Also on Windows when looking for the rc, look in getenv("APPDATA") instead of getenv("XDG_CONFIG_HOME"), which is mostly equivalent. Signed-off-by: Rafael Kitover --- src/rcfile.c | 4 ++++ src/utils.c | 4 +--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/rcfile.c b/src/rcfile.c index b9e2f091b..6f5085ac2 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -1725,7 +1725,11 @@ void do_rcfiles(void) parse_one_nanorc(); if (custom_nanorc == NULL) { +#ifndef _WIN32 const char *xdgconfdir = getenv("XDG_CONFIG_HOME"); +#else + const char *xdgconfdir = getenv("APPDATA"); +#endif get_homedir(); diff --git a/src/utils.c b/src/utils.c index 842d869d4..ed25b419f 100644 --- a/src/utils.c +++ b/src/utils.c @@ -36,9 +36,7 @@ void get_homedir(void) if (homedir == NULL) { const char *homenv = getenv("USERPROFILE"); - /* When HOME isn't set, or when we're root, get the home directory - * from the password file instead. */ - if (homenv == NULL || IsUserAnAdmin()) + if (homenv == NULL) homenv = getenv("ALLUSERSPROFILE"); /* Only set homedir if some home directory could be determined,