Annotation of Gnu-Mach/util/atoi.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Mach Operating System
                      3:  * Copyright (c) 1991,1990,1989 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  [email protected]
                     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:  *     Olivetti Mach Console driver v0.0
                     28:  *     Copyright Ing. C. Olivetti & C. S.p.A. 1988, 1989
                     29:  *     All rights reserved.
                     30:  *
                     31:  */
                     32: /*
                     33:   Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc.,
                     34: Cupertino, California.
                     35: 
                     36:                All Rights Reserved
                     37: 
                     38:   Permission to use, copy, modify, and distribute this software and
                     39: its documentation for any purpose and without fee is hereby
                     40: granted, provided that the above copyright notice appears in all
                     41: copies and that both the copyright notice and this permission notice
                     42: appear in supporting documentation, and that the name of Olivetti
                     43: not be used in advertising or publicity pertaining to distribution
                     44: of the software without specific, written prior permission.
                     45: 
                     46:   OLIVETTI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
                     47: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
                     48: IN NO EVENT SHALL OLIVETTI BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
                     49: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
                     50: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
                     51: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
                     52: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     53: */
                     54: 
                     55: /*
                     56:   Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
                     57: 
                     58:                All Rights Reserved
                     59: 
                     60: Permission to use, copy, modify, and distribute this software and
                     61: its documentation for any purpose and without fee is hereby
                     62: granted, provided that the above copyright notice appears in all
                     63: copies and that both the copyright notice and this permission notice
                     64: appear in supporting documentation, and that the name of Intel
                     65: not be used in advertising or publicity pertaining to distribution
                     66: of the software without specific, written prior permission.
                     67: 
                     68: INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
                     69: INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
                     70: IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
                     71: CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
                     72: LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
                     73: NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
                     74: WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     75: */
                     76: 
                     77: #include <util/atoi.h>
                     78: 
                     79: /*
                     80:  * mach_atoi:
                     81:  *
                     82:  *     This function converts an ascii string into an integer, and returns
                     83:  *     MACH_ATOI_DEFAULT if no integer was found.  Note that this is why we
                     84:  *     don't use the regular atio(), because ZERO is ZERO and not the
                     85:  *     MACH_ATOI_DEFAULT in all cases.
                     86:  *
                     87:  * input       : string
                     88:  * output      : a number or possibly MACH_ATOI_DEFAULT, and the count of
                     89:  *                characters consumed by the conversion
                     90:  *
                     91:  */
                     92: int
                     93: mach_atoi(cp, nump)
1.1.1.2 ! root       94: const u_char   *cp;
        !            95: int            *nump;
1.1       root       96: {
1.1.1.2 ! root       97:        int             number;
        !            98:        const u_char    *original;
1.1       root       99: 
                    100:        original = cp;
                    101:        for (number = 0; ('0' <= *cp) && (*cp <= '9'); cp++)
                    102:                number = (number * 10) + (*cp - '0');
                    103:        if (original == cp)
                    104:                *nump = MACH_ATOI_DEFAULT;
                    105:        else
                    106:                *nump = number;
                    107:        return(cp - original);
                    108: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.