23
23
* Contact the authors at <mandos@recompile.se>.
26
#define _GNU_SOURCE /* getline(), asprintf() */
28
#include <termios.h> /* struct termios, tcsetattr(),
29
TCSAFLUSH, tcgetattr(), ECHO */
30
#include <unistd.h> /* struct termios, tcsetattr(),
31
STDIN_FILENO, TCSAFLUSH,
32
tcgetattr(), ECHO, readlink() */
33
#include <signal.h> /* sig_atomic_t, raise(), struct
34
sigaction, sigemptyset(),
35
sigaction(), sigaddset(), SIGINT,
36
SIGQUIT, SIGHUP, SIGTERM,
26
#define _GNU_SOURCE /* vasprintf(),
27
program_invocation_short_name,
28
asprintf(), getline() */
29
#include <sys/types.h> /* sig_atomic_t, pid_t */
30
#include <stdbool.h> /* bool, false, true */
31
#include <argp.h> /* argp_program_version,
32
argp_program_bug_address,
34
struct argp_state, argp_state_help,
37
ARGP_HELP_EXIT_OK, ARGP_HELP_USAGE,
39
ARGP_ERR_UNKNOWN, argp_parse(),
40
ARGP_IN_ORDER, ARGP_NO_HELP */
41
#include <stdarg.h> /* va_list, va_start(), vfprintf() */
42
#include <stdio.h> /* vasprintf(), fprintf(), stderr,
43
vfprintf(), asprintf(), getline(),
44
stdin, feof(), clearerr(),
46
#include <errno.h> /* program_invocation_short_name,
47
errno, ENOENT, error_t, ENOMEM,
48
EINVAL, EBADF, ENOTTY, EFAULT,
49
EFBIG, EIO, ENOSPC, EINTR */
50
#include <string.h> /* strerror(), strrchr(), strcmp() */
51
#include <error.h> /* error() */
52
#include <stdlib.h> /* free(), realloc(), EXIT_SUCCESS,
53
EXIT_FAILURE, getenv() */
54
#include <unistd.h> /* access(), R_OK, ssize_t, close(),
55
read(), STDIN_FILENO, write(),
57
#include <dirent.h> /* struct dirent, scandir(),
59
#include <inttypes.h> /* uintmax_t, strtoumax() */
60
#include <iso646.h> /* or, and, not */
61
#include <fcntl.h> /* open(), O_RDONLY */
62
#include <stddef.h> /* NULL, size_t */
63
#include <termios.h> /* struct termios, tcgetattr(),
64
tcflag_t, ECHO, tcsetattr(),
66
#include <signal.h> /* struct sigaction, sigemptyset(),
67
sigaddset(), SIGINT, SIGHUP,
68
SIGTERM, SIG_IGN, SIG_DFL,
38
#include <stddef.h> /* NULL, size_t, ssize_t */
39
#include <sys/types.h> /* ssize_t, struct dirent, pid_t,
41
#include <stdlib.h> /* EXIT_SUCCESS, EXIT_FAILURE,
43
#include <dirent.h> /* scandir(), alphasort() */
44
#include <stdio.h> /* fprintf(), stderr, getline(),
45
stdin, feof(), fputc(), vfprintf(),
47
#include <errno.h> /* errno, EBADF, ENOTTY, EINVAL,
48
EFAULT, EFBIG, EIO, ENOSPC, EINTR
50
#include <error.h> /* error() */
51
#include <iso646.h> /* or, not */
52
#include <stdbool.h> /* bool, false, true */
53
#include <inttypes.h> /* strtoumax() */
54
#include <sys/stat.h> /* struct stat, lstat(), open() */
55
#include <string.h> /* strlen, rindex, memcmp, strerror()
57
#include <argp.h> /* struct argp_option, struct
58
argp_state, struct argp,
59
argp_parse(), error_t,
60
ARGP_KEY_ARG, ARGP_KEY_END,
62
#include <sysexits.h> /* EX_SOFTWARE, EX_OSERR,
63
EX_UNAVAILABLE, EX_IOERR, EX_OK */
64
#include <fcntl.h> /* open() */
65
#include <stdarg.h> /* va_list, va_start(), ... */
70
#include <sysexits.h> /* EX_OSERR, EX_USAGE, EX_UNAVAILABLE,
71
EX_IOERR, EX_OSFILE, EX_OK */
67
73
volatile sig_atomic_t quit_now = 0;
68
74
int signal_received;