diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2020-09-20 11:55:57 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2020-09-20 11:55:57 -0400 |
commit | 9a21e60f6629aa5d79d8d228faf1944d5b4a6e19 (patch) | |
tree | 8b5e1b9c1d20e73f6d7570252227dff18e53be9d /printf.c | |
parent | cac079d033259e72f0d11e81856c0266eada3b7f (diff) | |
download | bfs-9a21e60f6629aa5d79d8d228faf1944d5b4a6e19.tar.xz |
printf: Format the empty string for %l of non-links
It makes a difference if the format specifier has a width.
Diffstat (limited to 'printf.c')
-rw-r--r-- | printf.c | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -306,20 +306,21 @@ static int bfs_printf_k(FILE *file, const struct bfs_printf *directive, const st /** %l: link target */ static int bfs_printf_l(FILE *file, const struct bfs_printf *directive, const struct BFTW *ftwbuf) { - if (ftwbuf->type != BFTW_LNK) { - return 0; - } + char *buf = NULL; + const char *target = ""; - const struct bfs_stat *statbuf = bftw_cached_stat(ftwbuf, BFS_STAT_NOFOLLOW); - size_t len = statbuf ? statbuf->size : 0; + if (ftwbuf->type == BFTW_LNK) { + const struct bfs_stat *statbuf = bftw_cached_stat(ftwbuf, BFS_STAT_NOFOLLOW); + size_t len = statbuf ? statbuf->size : 0; - char *target = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, len); - if (!target) { - return -1; + target = buf = xreadlinkat(ftwbuf->at_fd, ftwbuf->at_path, len); + if (!target) { + return -1; + } } int ret = fprintf(file, directive->str, target); - free(target); + free(buf); return ret; } |