summaryrefslogtreecommitdiffstats
path: root/cmd-source-file.c
diff options
context:
space:
mode:
authornicm <nicm>2019-12-18 07:48:56 +0000
committernicm <nicm>2019-12-18 07:48:56 +0000
commitef54a08080ef7d721d05361bf10e27217c87590e (patch)
treed3950dccda0c24b06b71a207b6c8d97ea315aa94 /cmd-source-file.c
parentf8cb759bdbf767348dba1ae841a86f2bdafe3f25 (diff)
Do not rely on errno after glob(3) fails.
Diffstat (limited to 'cmd-source-file.c')
-rw-r--r--cmd-source-file.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/cmd-source-file.c b/cmd-source-file.c
index a07c27c7..6af1a6d0 100644
--- a/cmd-source-file.c
+++ b/cmd-source-file.c
@@ -130,7 +130,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
char *pattern, *cwd;
const char *path, *error;
glob_t g;
- int i;
+ int i, result;
u_int j;
cdata = xcalloc(1, sizeof *cdata);
@@ -158,9 +158,15 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item)
xasprintf(&pattern, "%s/%s", cwd, path);
log_debug("%s: %s", __func__, pattern);
- if (glob(pattern, 0, NULL, &g) != 0) {
- error = strerror(errno);
- if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) {
+ if ((result = glob(pattern, 0, NULL, &g)) != 0) {
+ if (result != GLOB_NOMATCH ||
+ (~flags & CMD_PARSE_QUIET)) {
+ if (result == GLOB_NOMATCH)
+ error = strerror(ENOENT);
+ else if (result == GLOB_NOSPACE)
+ error = strerror(ENOMEM);
+ else
+ error = strerror(EINVAL);
cmdq_error(item, "%s: %s", path, error);
retval = CMD_RETURN_ERROR;
}