summaryrefslogtreecommitdiffstats
path: root/printf.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2018-07-20 12:42:31 -0400
committerTavian Barnes <tavianator@tavianator.com>2018-07-20 12:48:03 -0400
commit510a7bd65c680fcf292493b5c00ce32c90a5155c (patch)
treedf51e7be095863de316e7e9b4877de6d9baeb690 /printf.c
parent45eafe9cf597c071029d61a9625bb96034d5aac9 (diff)
downloadbfs-510a7bd65c680fcf292493b5c00ce32c90a5155c.tar.xz
printf: Output ? for errors in %Y
Diffstat (limited to 'printf.c')
-rw-r--r--printf.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/printf.c b/printf.c
index 86804b8..6a87f99 100644
--- a/printf.c
+++ b/printf.c
@@ -377,6 +377,8 @@ static int bfs_printf_y(FILE *file, const struct bfs_printf_directive *directive
/** %Y: target type */
static int bfs_printf_Y(FILE *file, const struct bfs_printf_directive *directive, const struct BFTW *ftwbuf) {
+ int error = 0;
+
if (ftwbuf->typeflag != BFTW_LNK) {
return bfs_printf_y(file, directive, ftwbuf);
}
@@ -395,10 +397,19 @@ static int bfs_printf_Y(FILE *file, const struct bfs_printf_directive *directive
case ENOTDIR:
type = "N";
break;
+ default:
+ type = "?";
+ error = errno;
+ break;
}
}
- return fprintf(file, directive->str, type);
+ int ret = fprintf(file, directive->str, type);
+ if (error != 0) {
+ ret = -1;
+ errno = error;
+ }
+ return ret;
}
/**
@@ -798,16 +809,16 @@ error:
}
int bfs_printf(FILE *file, const struct bfs_printf *command, const struct BFTW *ftwbuf) {
- int ret = -1;
+ int ret = 0, error = 0;
for (struct bfs_printf_directive *directive = command->directives; directive; directive = directive->next) {
if (directive->fn(file, directive, ftwbuf) < 0) {
- goto done;
+ ret = -1;
+ error = errno;
}
}
- ret = 0;
-done:
+ errno = error;
return ret;
}