1 // Copyright © Tavian Barnes <tavianator@tavianator.com>
2 // SPDX-License-Identifier: 0BSD
5 * Implementation of -exec/-execdir/-ok/-okdir.
17 * Flags for the -exec actions.
20 /** Prompt the user before executing (-ok, -okdir). */
21 BFS_EXEC_CONFIRM = 1 << 0,
22 /** Run the command in the file's parent directory (-execdir, -okdir). */
23 BFS_EXEC_CHDIR = 1 << 1,
24 /** Pass multiple files at once to the command (-exec ... {} +). */
25 BFS_EXEC_MULTI = 1 << 2,
29 * Buffer for a command line to be executed.
32 /** Flags for this exec buffer. */
33 enum bfs_exec_flags flags;
35 /** The bfs context. */
36 const struct bfs_ctx *ctx;
37 /** Command line template. */
39 /** Command line template size. */
42 /** The built command line. */
44 /** Number of command line arguments. */
46 /** Capacity of argv. */
49 /** Current size of all arguments. */
51 /** Maximum arg_size before E2BIG. */
53 /** Lower bound for arg_max. */
56 /** A file descriptor for the working directory, for BFS_EXEC_CHDIR. */
58 /** The path to the working directory, for BFS_EXEC_CHDIR. */
60 /** Length of the working directory path. */
63 /** The ultimate return value for bfs_exec_finish(). */
68 * Parse an exec action.
71 * The (bfs) command line argument to parse.
73 * Any flags for this exec action.
77 * The parsed exec action, or NULL on failure.
79 struct bfs_exec *bfs_exec_parse(const struct bfs_ctx *ctx, char **argv, enum bfs_exec_flags flags);
82 * Execute the command for a file.
85 * The parsed exec action.
87 * The bftw() data for the current file.
88 * @return 0 if the command succeeded, -1 if it failed. If the command could
89 * be executed, -1 is returned, and errno will be non-zero. For
90 * BFS_EXEC_MULTI, errors will not be reported until bfs_exec_finish().
92 int bfs_exec(struct bfs_exec *execbuf, const struct BFTW *ftwbuf);
95 * Finish executing any commands.
98 * The parsed exec action.
99 * @return 0 on success, -1 if any errors were encountered.
101 int bfs_exec_finish(struct bfs_exec *execbuf);
104 * Free a parsed exec action.
106 void bfs_exec_free(struct bfs_exec *execbuf);