Add a POSIX directory walk #11

Merged
fputs merged 1 commit from fputs/dir into master 2026-11-05 09:54:33 -08:00 AGit
Owner

Adds a POSIX directory walk in lfdir.h. next skips . and .. and does not skip other dotfiles. Names are the directory entry, not a joined path, and there is no recursion. lf_path_join does not allocate. A short buffer or a NULL argument leaves the destination unchanged.

LfDir is a complete struct so the caller can own the handle on the stack. dir and name are private. A failed open does not write the handle, so a zeroed handle stays safe to close.

Empty a in lf_path_join yields b with no extra slash. a/ plus b is a/b.

Tests use mkdtemp under /tmp and remove the directory before the test returns.

Tested with -DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF. ctest --label-exclude slow: 26/26 passed.

Adds a POSIX directory walk in `lfdir.h`. `next` skips `.` and `..` and does not skip other dotfiles. Names are the directory entry, not a joined path, and there is no recursion. `lf_path_join` does not allocate. A short buffer or a NULL argument leaves the destination unchanged. `LfDir` is a complete struct so the caller can own the handle on the stack. `dir` and `name` are private. A failed `open` does not write the handle, so a zeroed handle stays safe to `close`. Empty `a` in `lf_path_join` yields `b` with no extra slash. `a/` plus `b` is `a/b`. Tests use `mkdtemp` under `/tmp` and remove the directory before the test returns. Tested with `-DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF`. `ctest --label-exclude slow`: 26/26 passed.
Add a POSIX directory walk
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 14s
b7e5d0e585
fputs force-pushed fputs/dir from b7e5d0e585
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 14s
to 8671a19723
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 15s
2026-11-05 09:39:15 -08:00
Compare
fputs force-pushed fputs/dir from 8671a19723
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 15s
to 29e36931ec
All checks were successful
test / test (pull_request) Successful in 14s
test / sanitize (pull_request) Successful in 18s
2026-11-05 09:45:18 -08:00
Compare
fputs merged commit 5131cd9630 into master 2026-11-05 09:54:33 -08:00
fputs referenced this pull request from a commit 2026-11-05 09:54:35 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fputs/libflint!11
No description provided.