Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F169826535
D42278.id129014.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D42278.id129014.diff
View Options
diff --git a/usr.bin/calendar/calendar.1 b/usr.bin/calendar/calendar.1
--- a/usr.bin/calendar/calendar.1
+++ b/usr.bin/calendar/calendar.1
@@ -215,9 +215,8 @@
.Pp
If the shared file is not referenced by a full pathname,
.Nm
-searches in the current (or home) directory first, and then in the
-directory
-.Pa /usr/share/calendar .
+searches in the same order of precedence described in
+.Sx FILES .
.Pp
Blank lines and text protected by the C comment syntax
.Ql /* ... */
diff --git a/usr.bin/calendar/io.c b/usr.bin/calendar/io.c
--- a/usr.bin/calendar/io.c
+++ b/usr.bin/calendar/io.c
@@ -48,6 +48,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
+#include <fcntl.h>
#include <libutil.h>
#include <locale.h>
#include <pwd.h>
@@ -115,9 +116,11 @@
static FILE *
cal_fopen(const char *file)
{
+ static int cwdfd = -1;
FILE *fp;
char *home = getenv("HOME");
unsigned int i;
+ int fd;
struct stat sb;
static bool warned = false;
static char calendarhome[MAXPATHLEN];
@@ -127,6 +130,30 @@
return (NULL);
}
+ /*
+ * On -a runs, we would have done a chdir() earlier on, but we also
+ * shouldn't have used the initial cwd anyways lest we bring
+ * unpredictable behavior upon us.
+ */
+ if (!doall && cwdfd == -1) {
+ cwdfd = open(".", O_DIRECTORY | O_PATH);
+ if (cwdfd == -1)
+ err(1, "open(cwd)");
+ }
+
+ /*
+ * Check $PWD first as documented.
+ */
+ if (cwdfd != -1 && (fd = openat(cwdfd, file, O_RDONLY)) != -1) {
+ if ((fp = fdopen(fd, "r")) == NULL)
+ err(1, "fdopen(%s)", file);
+
+ cal_home = NULL;
+ cal_dir = NULL;
+ cal_file = file;
+ return (fp);
+ }
+
if (chdir(home) != 0) {
warnx("Cannot enter home directory \"%s\"", home);
return (NULL);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Sep 3, 4:49 PM (8 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
38134691
Default Alt Text
D42278.id129014.diff (1 KB)
Attached To
Mode
D42278: calendar: correct the search order for files
Attached
Detach File
Event Timeline
Log In to Comment