The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/smbfs/getopt.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*
    2  * getopt.c
    3  */
    4 
    5 #include <linux/kernel.h>
    6 #include <linux/string.h>
    7 
    8 #include "getopt.h"
    9 
   10 /**
   11  *      smb_getopt - option parser
   12  *      @caller: name of the caller, for error messages
   13  *      @options: the options string
   14  *      @opts: an array of &struct option entries controlling parser operations
   15  *      @optopt: output; will contain the current option
   16  *      @optarg: output; will contain the value (if one exists)
   17  *      @flag: output; may be NULL; should point to a long for or'ing flags
   18  *      @value: output; may be NULL; will be overwritten with the integer value
   19  *              of the current argument.
   20  *
   21  *      Helper to parse options on the format used by mount ("a=b,c=d,e,f").
   22  *      Returns opts->val if a matching entry in the 'opts' array is found,
   23  *      0 when no more tokens are found, -1 if an error is encountered.
   24  */
   25 int smb_getopt(char *caller, char **options, struct option *opts,
   26                char **optopt, char **optarg, unsigned long *flag,
   27                unsigned long *value)
   28 {
   29         char *token;
   30         char *val;
   31         int i;
   32 
   33         do {
   34                 if ((token = strsep(options, ",")) == NULL)
   35                         return 0;
   36         } while (*token == '\0');
   37         *optopt = token;
   38 
   39         *optarg = NULL;
   40         if ((val = strchr (token, '=')) != NULL) {
   41                 *val++ = 0;
   42                 if (value)
   43                         *value = simple_strtoul(val, NULL, 0);
   44                 *optarg = val;
   45         }
   46 
   47         for (i = 0; opts[i].name != NULL; i++) {
   48                 if (!strcmp(opts[i].name, token)) {
   49                         if (!opts[i].flag && (!val || !*val)) {
   50                                 printk("%s: the %s option requires an argument\n",
   51                                        caller, token);
   52                                 return -1;
   53                         }
   54 
   55                         if (flag && opts[i].flag)
   56                                 *flag |= opts[i].flag;
   57 
   58                         return opts[i].val;
   59                 }
   60         }
   61         printk("%s: Unrecognized mount option %s\n", caller, token);
   62         return -1;
   63 }

Cache object: 172752305c4520fcb07c7b9eed08e810


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.