libutil/recurse: Use a single path buffer, and directory fd

This way, we don't use PATH_MAX bytes on the stack per path component,
and don't have to keep copying the complete path around.
This commit is contained in:
Michael Forney
2019-12-22 13:53:46 -08:00
parent 039b54aa51
commit edbcc223ea
10 changed files with 72 additions and 57 deletions

9
fs.h
View File

@@ -1,4 +1,5 @@
/* See LICENSE file for copyright and license details. */
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
@@ -9,7 +10,9 @@ struct history {
};
struct recursor {
void (*fn)(const char *, struct stat *st, void *, struct recursor *);
void (*fn)(int, const char *, struct stat *, void *, struct recursor *);
char path[PATH_MAX];
size_t pathlen;
struct history *hist;
int depth;
int maxdepth;
@@ -37,7 +40,7 @@ extern int rm_status;
extern int recurse_status;
void recurse(const char *, void *, struct recursor *);
void recurse(int, const char *, void *, struct recursor *);
int cp(const char *, const char *, int);
void rm(const char *, struct stat *st, void *, struct recursor *);
void rm(int, const char *, struct stat *st, void *, struct recursor *);