From 6f139d796f0585c7d663f4178f0053a6f4c0af8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20E=C3=9Fer?= Date: Sat, 12 Dec 2020 11:51:29 +0000 Subject: [PATCH] Use getlocalbase() instead of compiled in LOCALBASE to locate calendars --- usr.bin/calendar/io.c | 10 ++++++++-- usr.bin/calendar/pathnames.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c index b9fef2684091..adea085cf3da 100644 --- a/usr.bin/calendar/io.c +++ b/usr.bin/calendar/io.c @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -121,6 +122,7 @@ cal_fopen(const char *file) unsigned int i; struct stat sb; static bool warned = false; + char calendarhome[MAXPATHLEN]; if (home == NULL || *home == '\0') { warnx("Cannot get home directory"); @@ -133,12 +135,16 @@ cal_fopen(const char *file) } for (i = 0; i < nitems(calendarHomes); i++) { - if (chdir(calendarHomes[i]) != 0) + if (snprintf(calendarhome, sizeof (calendarhome), calendarHomes[i], + getlocalbase()) >= (int)sizeof (calendarhome)) + continue; + + if (chdir(calendarhome) != 0) continue; if ((fp = fopen(file, "r")) != NULL) { cal_home = home; - cal_dir = calendarHomes[i]; + cal_dir = calendarhome; cal_file = file; return (fp); } diff --git a/usr.bin/calendar/pathnames.h b/usr.bin/calendar/pathnames.h index 95f41a25758f..fa46eb0c7e50 100644 --- a/usr.bin/calendar/pathnames.h +++ b/usr.bin/calendar/pathnames.h @@ -35,4 +35,4 @@ #include #define _PATH_INCLUDE "/usr/share/calendar" -#define _PATH_INCLUDE_LOCAL _PATH_LOCALBASE "/share/calendar" +#define _PATH_INCLUDE_LOCAL "%s/share/calendar"