summaryrefslogtreecommitdiff
path: root/src/util/loop_files.h
blob: 8add11d1e463b65ef0b354a46fe0c3b6ac58b661 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#pragma once

#include <stdbool.h>

#include "io/read_file.h"

/// Call `callback` for every argument provided by `args`.
/// The arguments are interpreted as filenames, "-" is interpreted as stdin.
/// For every argument the given filename is read into a `struct filebuf*`,
/// which the callee should free (using `free_filebuf`).
///
/// If the list of arguments is empty, `callback` is called once with stdin read
/// into a `filebuf*` and `fname = NULL`.
///
/// `callback` is expected to return the exit code for the program.
/// If the exit code is positive, the program will exit immediately with the
/// provided exit code.
/// If the exit code is negative enumeration is continued, but after enumeration
/// the function will return the exit code negated (i.e. the function will
/// never return a negative integer).
int loop_files(char **args, int (*callback)(struct filebuf*, char *fname, bool isstdin));