|
|
6909f1 |
diff -up ./top/top.c.ori ./top/top.c
|
|
|
6909f1 |
--- ./top/top.c.ori 2019-02-27 17:23:48.060408215 +0100
|
|
|
6909f1 |
+++ ./top/top.c 2019-02-28 15:28:11.321927877 +0100
|
|
|
6909f1 |
@@ -3437,6 +3437,20 @@ static int config_cvt (WIN_t *q) {
|
|
|
6909f1 |
} // end: config_cvt
|
|
|
6909f1 |
|
|
|
6909f1 |
|
|
|
6909f1 |
+static int snprintf_Rc_name (const char *const format, ...) __attribute__((format(printf,1,2)));
|
|
|
6909f1 |
+static int snprintf_Rc_name (const char *const format, ...) {
|
|
|
6909f1 |
+ int len;
|
|
|
6909f1 |
+ va_list ap;
|
|
|
6909f1 |
+ va_start(ap, format);
|
|
|
6909f1 |
+ len = vsnprintf(Rc_name, sizeof(Rc_name), format, ap);
|
|
|
6909f1 |
+ va_end(ap);
|
|
|
6909f1 |
+ if (len <= 0 || (size_t)len >= sizeof(Rc_name)) {
|
|
|
6909f1 |
+ Rc_name[0] = '\0';
|
|
|
6909f1 |
+ return 0;
|
|
|
6909f1 |
+ }
|
|
|
6909f1 |
+ return len;
|
|
|
6909f1 |
+}
|
|
|
6909f1 |
+
|
|
|
6909f1 |
/*
|
|
|
6909f1 |
* Build the local RC file name then try to read both of 'em.
|
|
|
6909f1 |
* 'SYS_RCFILESPEC' contains two lines consisting of the secure
|
|
|
6909f1 |
@@ -3458,8 +3472,18 @@ static void configs_read (void) {
|
|
|
6909f1 |
FILE *fp;
|
|
|
6909f1 |
int i;
|
|
|
6909f1 |
|
|
|
6909f1 |
+ Rc_name[0] = '\0'; // "fopen() shall fail if pathname is an empty string."
|
|
|
6909f1 |
p = getenv("HOME");
|
|
|
6909f1 |
- snprintf(Rc_name, sizeof(Rc_name), "%s/.%src", (p && *p) ? p : ".", Myname);
|
|
|
6909f1 |
+
|
|
|
6909f1 |
+ if (!p || p[0] != '/') {
|
|
|
6909f1 |
+ const struct passwd *const pwd = getpwuid(getuid());
|
|
|
6909f1 |
+ if (!pwd || !(p = pwd->pw_dir) || p[0] != '/') {
|
|
|
6909f1 |
+ p = NULL;
|
|
|
6909f1 |
+ }
|
|
|
6909f1 |
+ }
|
|
|
6909f1 |
+ if (p) {
|
|
|
6909f1 |
+ snprintf_Rc_name("%s/.%src", p, Myname);
|
|
|
6909f1 |
+ }
|
|
|
6909f1 |
|
|
|
6909f1 |
fp = fopen(SYS_RCFILESPEC, "r");
|
|
|
6909f1 |
if (fp) {
|