Add atoll(3) to conform POSIX and C99

This commit is contained in:
Andrey A. Chernov 2001-11-28 01:22:08 +00:00
parent 7e302fc7a2
commit 59d01330c4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=87017
4 changed files with 70 additions and 2 deletions

View File

@ -94,6 +94,7 @@ int atexit __P((void (*)(void)));
double atof __P((const char *));
int atoi __P((const char *));
long atol __P((const char *));
long atoll __P((const char *));
void *bsearch __P((const void *, const void *, size_t,
size_t, int (*)(const void *, const void *)));
void *calloc __P((size_t, size_t));

View File

@ -4,7 +4,8 @@
# machine-independent stdlib sources
.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/stdlib ${.CURDIR}/../libc/stdlib
MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \
MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c \
bsearch.c calloc.c div.c \
exit.c getenv.c getopt.c getsubopt.c hcreate.c heapsort.c \
imaxabs.c imaxdiv.c labs.c ldiv.c llabs.c lldiv.c \
malloc.c merge.c putenv.c qsort.c radixsort.c rand.c random.c \
@ -33,6 +34,7 @@ MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \
malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \
realpath.3 strfmon.3 strtod.3 strtol.3 strtoul.3 system.3 tsearch.3
MLINKS+=atol.3 atoll.3
MLINKS+=getenv.3 putenv.3 getenv.3 setenv.3 getenv.3 unsetenv.3
MLINKS+=hcreate.3 hdestroy.3 hcreate.3 hsearch.3
MLINKS+=qsort.3 heapsort.3 qsort.3 mergesort.3

View File

@ -40,7 +40,7 @@
.Dt ATOL 3
.Os
.Sh NAME
.Nm atol
.Nm atol , atoll
.Nd convert
.Tn ASCII
string to long integer
@ -50,6 +50,8 @@ string to long integer
.In stdlib.h
.Ft long
.Fn atol "const char *nptr"
.Ft long long
.Fn atoll "const char *nptr"
.Sh DESCRIPTION
The
.Fn atol
@ -63,6 +65,19 @@ It is equivalent to:
.Bd -literal -offset indent
strtol(nptr, (char **)NULL, 10);
.Ed
.Pp
The
.Fn atoll
function converts the initial portion of the string pointed to by
.Ar nptr
to
.Em long long integer
representation.
.Pp
It is equivalent to:
.Bd -literal -offset indent
strtoll(nptr, (char **)NULL, 10);
.Ed
.Sh SEE ALSO
.Xr atof 3 ,
.Xr atoi 3 ,
@ -75,3 +90,9 @@ The
function
conforms to
.St -isoC .
.Pp
The
.Fn atoll
function
conforms to
.St -isoC-99 .

44
lib/libc/stdlib/atoll.c Normal file
View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $FreeBSD$
*/
#include <stddef.h>
#include <stdlib.h>
long long
atoll(str)
const char *str;
{
return(strtoll(str, (char **)NULL, 10));
}