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/kern/sscanf.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  * Mach Operating System
    3  * Copyright (c) 1993 Carnegie Mellon University
    4  * All Rights Reserved.
    5  * 
    6  * Permission to use, copy, modify and distribute this software and its
    7  * documentation is hereby granted, provided that both the copyright
    8  * notice and this permission notice appear in all copies of the
    9  * software, derivative works or modified versions, and any portions
   10  * thereof, and that both notices appear in supporting documentation.
   11  * 
   12  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   13  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
   14  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   15  * 
   16  * Carnegie Mellon requests users of this software to return to
   17  * 
   18  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   19  *  School of Computer Science
   20  *  Carnegie Mellon University
   21  *  Pittsburgh PA 15213-3890
   22  * 
   23  * any improvements or extensions that they make and grant Carnegie Mellon
   24  * the rights to redistribute these changes.
   25  */
   26 /*
   27  * HISTORY
   28  * $Log:        sscanf.c,v $
   29  * Revision 2.4  93/11/17  17:24:17  dbg
   30  *      Converted to stdarg.
   31  *      [93/10/28            dbg]
   32  * 
   33  * Revision 2.3  93/03/26  17:54:53  mrt
   34  *      Lint.
   35  *      [93/03/23            af]
   36  * 
   37  * Revision 2.2  93/03/09  10:55:32  danner
   38  *      Created.
   39  *      [93/03/06  14:35:41  af]
   40  * 
   41  */
   42 /*
   43  *      File: sscanf.c
   44  *      Author: Alessandro Forin, Carnegie Mellon University
   45  *      Date:   3/93
   46  *
   47  *      Parse trivially simple strings
   48  */
   49 
   50 #include <mach/std_types.h>
   51 #include <sys/stdarg.h>
   52 #include <kern/kern_io.h>
   53 
   54 /*
   55  * All I need is a miracle ...
   56  * to keep this from growing like all the other sscanf!
   57  */
   58 int
   59 sscanf(
   60         const char      *input,
   61         const char      *fmt,
   62         ...)
   63 {
   64         va_list         vp;
   65         register        int c;
   66         long            n;
   67         boolean_t       neg;
   68         const unsigned  char    *start = input;
   69 
   70         va_start(vp, fmt);
   71 
   72         while ((c = *fmt++) != '\0') {
   73 
   74             if (c != '%' && c == *input) {
   75                 input++;
   76                 continue;
   77             }
   78 
   79             if (c != '%')
   80                 break;  /* mismatch */
   81 
   82             c = *fmt++;
   83 
   84             switch (c) {
   85 
   86             case 'd':
   87                 n = 0;
   88                 c = *input++;
   89 
   90                 neg =  c == '-';
   91                 if (neg) c = *input++;
   92 
   93                 while (c >= '' && c <= '9') {
   94                     n = n * 10 + (c - '');
   95                     c = *input++;
   96                 }
   97                 input--;        /* retract lookahead */
   98 
   99                 if (neg) n = -n;
  100 
  101                 /* done, store it away */
  102                 {
  103                         int     *p = va_arg(vp, int *);
  104                         *p = n;
  105                 }
  106 
  107                 break;
  108 
  109             default:
  110                 break;
  111             }
  112         }
  113 
  114         va_end(vp);     
  115 
  116         return (vm_offset_t)input - (vm_offset_t)start;
  117 }

Cache object: 9eefc592b7d5df4cf4bd8cf25670bb75


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