]> git.ipfire.org Git - thirdparty/glibc.git/blame - manual/examples/subopt.c
update from main archive 970121
[thirdparty/glibc.git] / manual / examples / subopt.c
CommitLineData
2064087b
RM
1#include <stdio.h>
2#include <stdlib.h>
3
4int do_all;
5const char *type;
6int read_size;
7int write_size;
8int read_only;
9
10enum
11{
12 RO_OPTION = 0,
13 RW_OPTION,
14 READ_SIZE_OPTION,
15 WRITE_SIZE_OPTION
16};
17
18const char *mount_opts[] =
19{
20 [RO_OPTION] = "ro",
21 [RW_OPTION] = "rw",
22 [READ_SIZE_OPTION] = "rsize",
23 [WRITE_SIZE_OPTION] = "wsize"
24};
25
26int
27main (int argc, char *argv[])
28{
29 char *subopts, *value;
30 int opt;
31
1ef32c3d 32 while ((opt = getopt (argc, argv, "at:o:")) != -1)
2064087b
RM
33 switch (opt)
34 {
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))
45 {
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;
66 }
67 break;
68 default:
69 abort ();
70 }
71
72 /* Do the real work. */
73
74 return 0;
75}