]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kern/sscanf.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 * @OSF_FREE_COPYRIGHT@
28 * Revision 1.1.1.1 1998/09/22 21:05:32 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:25:56 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.1.8.2 1997/02/12 12:52:33 stephen
35 * New file, reimplemented to be sure of copyright status
36 * Initially only supports character matching and '%d'
37 * [1997/02/12 12:43:09 stephen]
43 #include <kern/misc_protos.h>
45 #define isdigit(c) ((unsigned) ((c) - '0') < 10U)
48 * Scan items from a string in accordance with a format. This is much
49 * simpler than the C standard function: it only recognises %d without a
50 * field width, and does not treat space in the format string or the
51 * input any differently from other characters. The return value is the
52 * number of characters from the input string that were successfully
53 * scanned, not the number of format items matched as in standard sscanf.
54 * e.mcmanus@opengroup.org, 12 Feb 97
57 sscanf(const char *str
, const char *format
, ...)
59 const char *start
= str
;
62 va_start(args
, format
);
63 for ( ; *format
!= '\0'; format
++) {
64 if (*format
== '%' && format
[1] == 'd') {
78 value
= (value
* 10) - (*str
- '0');
80 } while (isdigit(*str
));
83 valp
= va_arg(args
, int *);
86 } else if (*format
== *str
) {