bore

basic core utilities (PD)
git clone git://bvnf.space/bore.git
Log | Files | Refs | README

commit a5924f2c4c0c4d41243c1ae70af556cc1799a876
parent d498abd9e618e2fe70bb2bd7970b3b349a3af040
Author: phoebos <ben@bvnf.space>
Date:   Sat,  1 Oct 2022 22:44:16 +0100

find: add (naive version)

Diffstat:
M.gitignore | 1+
MTODO.posix | 2+-
Afind.c | 29+++++++++++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -2,6 +2,7 @@ cat echo ed false +find grep head ls diff --git a/TODO.posix b/TODO.posix @@ -36,7 +36,7 @@ [ ] expr [x] false [ ] file -[ ] find +[.] find [ ] fold [ ] fort77 [ ] fuser diff --git a/find.c b/find.c @@ -0,0 +1,29 @@ +#include <errno.h> +#include <ftw.h> +#include <stdio.h> +#include <string.h> + +int +foreach(const char *name, const struct stat *sb, int tflag, struct FTW *ftwbuf) { + printf("%s\n", name); + /* fnmatch + * detect infinite loops + */ + return 0; +} + +int +main(int argc, char **argv) { + char *argv0 = argv[0]; + if (argc < 2) { + fprintf(stderr, "usage: %s path...\n", argv0); + return 1; + } + while (*(++argv)) { + if (nftw(*argv, foreach, 20, 0) != 0) { + fprintf(stderr, "%s: %s: %s\n", argv0, *argv, strerror(errno)); + return 1; + } + } + return 0; +}