Commit Graph

7 Commits

Author SHA1 Message Date
Xavier Del Campo Romero 59e17afe29
cftw: Allow user callback to stop recursive search
So far, cftw would search through all directories and files recursively,
until all objects are processed. However, it is interesting for the user
callback to be able to stop this process under specific circumstances.

Now, cftw will pass a pointer to a bool, initialised to false by
default, that can be optionally assigned to true by the user
callback.

Future commits will make use of this feature. For example, this will be
used to limit the number of search results when a user enters a search
term that is too generic and would otherwise generate a large amount of
search results.
2023-07-11 13:27:49 +02:00
Xavier Del Campo Romero 74ca76a58f
cftw: Allow directories to call the user callback
This provides a few benefits:

- This will allow searching for directories by name.
- Future commits will allow to remove files and directories, so this
  change was also required for cftw.
2023-07-08 02:30:31 +02:00
Xavier Del Campo Romero 74b7f7a902
cftw.c: Check errors from readdir(3)
According to POSIX.1-2017, applications are advised to assign errno(3)
to 0 before a call to readdir(3), and compare errno(3) after the call to
check for errors.
2023-07-06 01:56:43 +02:00
Xavier Del Campo Romero 6e9ce3a25b
ctfw.c: Avoid trailing forward slash
Otherwise, this would generate strings such as "directory//resource" if
dirpath contained a trailing slash, which could be problematic for users
relying on ctfw.
2023-06-06 03:48:51 +02:00
Xavier Del Campo Romero 95a0adfe78
cftw.c: Add missing portability definition 2023-05-28 12:07:38 +02:00
Xavier Del Campo Romero f33e1c9053
cftw.c: Add missing call to closedir(2) 2023-03-07 12:36:27 +01:00
Xavier Del Campo Romero 804b8841f3
Add cftw
POSIX functions ftw(3) and nftw(3) do not allow passing an opaque
pointer to the callback they call, so it forces the use of statically
allocated data.

ctfw (from "custom ftw") is a custom implementation that solves this,
while also removing unneeded stuff.

This function will be used by future commits.
2023-03-06 05:06:30 +01:00