add missing files
[glibc.git] / manual / examples / subopt.c
blob4a89f6441ef12d34715449ff36253b268079104a
1 #include <stdio.h>
2 #include <stdlib.h>
4 int do_all;
5 const char *type;
6 int read_size;
7 int write_size;
8 int read_only;
10 enum
12 RO_OPTION = 0,
13 RW_OPTION,
14 READ_SIZE_OPTION,
15 WRITE_SIZE_OPTION
18 const char *mount_opts[] =
20 [RO_OPTION] = "ro",
21 [RW_OPTION] = "rw",
22 [READ_SIZE_OPTION] = "rsize",
23 [WRITE_SIZE_OPTION] = "wsize"
26 int
27 main (int argc, char *argv[])
29 char *subopts, *value;
30 int opt;
32 while ((opt = getopt (argc, argv, "at:o:")) != EOF)
33 switch (opt)
35 case 'a':
36 do_all = 1;
37 break;
38 case 't':
39 type = optarg;
40 break;
41 case 'o':
42 subopts = optarg;
43 while (*subopts != '\0')
44 switch (getsubopt (&subopts, mount_opts, &value))
46 case RO_OPTION:
47 read_only = 1;
48 break;
49 case RW_OPTION:
50 read_only = 0;
51 break;
52 case READ_SIZE_OPTION:
53 if (value == NULL)
54 abort ();
55 read_size = atoi (value);
56 break;
57 case WRITE_SIZE_OPTION:
58 if (value == NULL)
59 abort ();
60 write_size = atoi (value);
61 break;
62 default:
63 /* Unknown suboption. */
64 printf ("Unknown suboption `%s'\n", value);
65 break;
67 break;
68 default:
69 abort ();
72 /* Do the real work. */
74 return 0;