Refer to C23 in place of C2X in glibc
[glibc.git] / posix / tst-getopt_long1.c
blob6d8ef02ca4073ea58714c50cf91c3cb33bcbc6f2
1 static void do_prepare (void);
2 #define PREPARE(argc, argv) do_prepare ()
3 static int do_test (void);
4 #define TEST_FUNCTION do_test ()
5 #include "../test-skeleton.c"
8 static char *fname;
11 static void
12 do_prepare (void)
14 if (create_temp_file ("tst-getopt_long1", &fname) < 0)
16 printf ("cannot create temp file: %m\n");
17 exit (1);
22 static const struct option opts[] =
24 { "one", no_argument, NULL, '1' },
25 { "two", no_argument, NULL, '2' },
26 { "one-one", no_argument, NULL, '3' },
27 { "four", no_argument, NULL, '4' },
28 { "onto", no_argument, NULL, '5' },
29 { NULL, 0, NULL, 0 }
33 static int
34 do_test (void)
36 if (freopen (fname, "w+", stderr) == NULL)
38 printf ("freopen failed: %m\n");
39 return 1;
42 char *argv[] = { (char *) "program", (char *) "--on" };
43 int argc = 2;
45 int c = getopt_long (argc, argv, "12345", opts, NULL);
46 printf ("return value: %c\n", c);
48 rewind (stderr);
49 char *line = NULL;
50 size_t len = 0;
51 if (getline (&line, &len, stderr) < 0)
53 printf ("cannot read stderr redirect: %m\n");
54 return 1;
56 printf ("message = \"%s\"\n", line);
58 static const char expected[] = "\
59 program: option '--on' is ambiguous; possibilities: '--one' '--one-one' '--onto'\n";
61 return c != '?' || strcmp (line, expected) != 0;