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/lib/cmdline.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  * linux/lib/cmdline.c
    3  * Helper functions generally used for parsing kernel command line
    4  * and module options.
    5  *
    6  * Code and copyrights come from init/main.c and arch/i386/kernel/setup.c.
    7  *
    8  * This source code is licensed under the GNU General Public License,
    9  * Version 2.  See the file COPYING for more details.
   10  *
   11  * GNU Indent formatting options for this file: -kr -i8 -npsl -pcs
   12  *
   13  */
   14 
   15 #include <linux/module.h>
   16 #include <linux/kernel.h>
   17 #include <linux/string.h>
   18 
   19 
   20 /**
   21  *      get_option - Parse integer from an option string
   22  *      @str: option string
   23  *      @pint: (output) integer value parsed from @str
   24  *
   25  *      Read an int from an option string; if available accept a subsequent
   26  *      comma as well.
   27  *
   28  *      Return values:
   29  *      0 : no int in string
   30  *      1 : int found, no subsequent comma
   31  *      2 : int found including a subsequent comma
   32  */
   33 
   34 int get_option (char **str, int *pint)
   35 {
   36         char *cur = *str;
   37 
   38         if (!cur || !(*cur))
   39                 return 0;
   40         *pint = simple_strtol (cur, str, 0);
   41         if (cur == *str)
   42                 return 0;
   43         if (**str == ',') {
   44                 (*str)++;
   45                 return 2;
   46         }
   47 
   48         return 1;
   49 }
   50 
   51 /**
   52  *      get_options - Parse a string into a list of integers
   53  *      @str: String to be parsed
   54  *      @nints: size of integer array
   55  *      @ints: integer array
   56  *
   57  *      This function parses a string containing a comma-separated
   58  *      list of integers.  The parse halts when the array is
   59  *      full, or when no more numbers can be retrieved from the
   60  *      string.
   61  *
   62  *      Return value is the character in the string which caused
   63  *      the parse to end (typically a null terminator, if @str is
   64  *      completely parseable).
   65  */
   66  
   67 char *get_options (char *str, int nints, int *ints)
   68 {
   69         int res, i = 1;
   70 
   71         while (i < nints) {
   72                 res = get_option (&str, ints + i);
   73                 if (res == 0)
   74                         break;
   75                 i++;
   76                 if (res == 1)
   77                         break;
   78         }
   79         ints[0] = i - 1;
   80         return (str);
   81 }
   82 
   83 /**
   84  *      memparse - parse a string with mem suffixes into a number
   85  *      @ptr: Where parse begins
   86  *      @retptr: (output) Pointer to next char after parse completes
   87  *
   88  *      Parses a string into a number.  The number stored at @ptr is
   89  *      potentially suffixed with %K (for kilobytes, or 1024 bytes),
   90  *      %M (for megabytes, or 1048576 bytes), or %G (for gigabytes, or
   91  *      1073741824).  If the number is suffixed with K, M, or G, then
   92  *      the return value is the number multiplied by one kilobyte, one
   93  *      megabyte, or one gigabyte, respectively.
   94  */
   95 
   96 unsigned long long memparse (char *ptr, char **retptr)
   97 {
   98         unsigned long long ret = simple_strtoull (ptr, retptr, 0);
   99 
  100         switch (**retptr) {
  101         case 'G':
  102         case 'g':
  103                 ret <<= 10;
  104         case 'M':
  105         case 'm':
  106                 ret <<= 10;
  107         case 'K':
  108         case 'k':
  109                 ret <<= 10;
  110                 (*retptr)++;
  111         default:
  112                 break;
  113         }
  114         return ret;
  115 }
  116 
  117 
  118 EXPORT_SYMBOL(memparse);
  119 EXPORT_SYMBOL(get_option);
  120 EXPORT_SYMBOL(get_options);

Cache object: fd657065527f7dc3380acc79528accc5


[ 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.