Back to index

glibc  2.9
subopt.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <unistd.h>
00004 
00005 int do_all;
00006 const char *type;
00007 int read_size;
00008 int write_size;
00009 int read_only;
00010 
00011 enum
00012 {
00013   RO_OPTION = 0,
00014   RW_OPTION,
00015   READ_SIZE_OPTION,
00016   WRITE_SIZE_OPTION,
00017   THE_END
00018 };
00019 
00020 const char *mount_opts[] =
00021 {
00022   [RO_OPTION] = "ro",
00023   [RW_OPTION] = "rw",
00024   [READ_SIZE_OPTION] = "rsize",
00025   [WRITE_SIZE_OPTION] = "wsize",
00026   [THE_END] = NULL
00027 };
00028 
00029 int
00030 main (int argc, char *argv[])
00031 {
00032   char *subopts, *value;
00033   int opt;
00034 
00035   while ((opt = getopt (argc, argv, "at:o:")) != -1)
00036     switch (opt)
00037       {
00038       case 'a':
00039         do_all = 1;
00040         break;
00041       case 't':
00042         type = optarg;
00043         break;
00044       case 'o':
00045         subopts = optarg;
00046         while (*subopts != '\0')
00047           switch (getsubopt (&subopts, mount_opts, &value))
00048             {
00049             case RO_OPTION:
00050               read_only = 1;
00051               break;
00052             case RW_OPTION:
00053               read_only = 0;
00054               break;
00055             case READ_SIZE_OPTION:
00056               if (value == NULL)
00057                 abort ();
00058               read_size = atoi (value);
00059               break;
00060             case WRITE_SIZE_OPTION:
00061               if (value == NULL)
00062                 abort ();
00063               write_size = atoi (value);
00064               break;
00065             default:
00066               /* Unknown suboption.  */
00067               printf ("Unknown suboption `%s'\n", value);
00068               break;
00069             }
00070         break;
00071       default:
00072         abort ();
00073       }
00074 
00075   /* Do the real work.  */
00076 
00077   return 0;
00078 }