1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 *
4 * This test program prints errno messages to allow for portable
5 * verification of error messages.
6 *
7 * Copyright (C) 2019 Patrick Steinhardt <ps@pks.im
8 */
9
10 #include <errno.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #define E(x) { #x, x }
16 static struct {
17 const char *str;
18 int error;
19 } errors[] = {
20 E(ENOENT),
21 E(ENOTTY),
22 E(EILSEQ),
23 E(EINVAL),
24 };
25
26 int main(int argc, const char *argv[])
27 {
28 size_t i;
29
30 if (argc != 2) {
31 fprintf(stderr, "USAGE: %s <errno>\n", argv[0]);
32 return -1;
33 }
34
35 for (i = 0; i < sizeof(errors)/sizeof(*errors); i++) {
36 if (strcmp(errors[i].str, argv[1]) != 0)
37 continue;
38 puts(strerror(errors[i].error));
39 return 0;
40 }
41
42 fprintf(stderr, "Invalid errno: %s\n", argv[1]);
43 return -1;
44 }