* sysdeps/mach/hurd/i386/tls.h (THREAD_DTV): Changed type of _DTV
[glibc.git] / manual / examples / subopt.c
blob287fe8c4959b63ccd1ab25b1c2bf16b0b60ba0d3
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
5 int do_all;
6 const char *type;
7 int read_size;
8 int write_size;
9 int read_only;
11 enum
13 RO_OPTION = 0,
14 RW_OPTION,
15 READ_SIZE_OPTION,
16 WRITE_SIZE_OPTION,
17 THE_END
20 const char *mount_opts[] =
22 [RO_OPTION] = "ro",
23 [RW_OPTION] = "rw",
24 [READ_SIZE_OPTION] = "rsize",
25 [WRITE_SIZE_OPTION] = "wsize",
26 [THE_END] = NULL
29 int
30 main (int argc, char *argv[])
32 char *subopts, *value;
33 int opt;
35 while ((opt = getopt (argc, argv, "at:o:")) != -1)
36 switch (opt)
38 case 'a':
39 do_all = 1;
40 break;
41 case 't':
42 type = optarg;
43 break;
44 case 'o':
45 subopts = optarg;
46 while (*subopts != '\0')
47 switch (getsubopt (&subopts, mount_opts, &value))
49 case RO_OPTION:
50 read_only = 1;
51 break;
52 case RW_OPTION:
53 read_only = 0;
54 break;
55 case READ_SIZE_OPTION:
56 if (value == NULL)
57 abort ();
58 read_size = atoi (value);
59 break;
60 case WRITE_SIZE_OPTION:
61 if (value == NULL)
62 abort ();
63 write_size = atoi (value);
64 break;
65 default:
66 /* Unknown suboption. */
67 printf ("Unknown suboption `%s'\n", value);
68 break;
70 break;
71 default:
72 abort ();
75 /* Do the real work. */
77 return 0;