From 88b87e338a755e5995b0a96d9b18b1c3b08deef6 Mon Sep 17 00:00:00 2001 From: Simon Schubert Date: Sat, 24 Nov 2007 00:54:25 +0000 Subject: [PATCH] Add llabs(3). Obtained-From: FreeBSD --- lib/libc/stdlib/Makefile.inc | 6 ++--- lib/libc/stdlib/llabs.3 | 63 ++++++++++++++++++++++++++++++++++++++++++++ lib/libc/stdlib/llabs.c | 37 ++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 3 deletions(-) create mode 100644 lib/libc/stdlib/llabs.3 create mode 100644 lib/libc/stdlib/llabs.c diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index b9b4459a4c..a15e388dc8 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -1,13 +1,13 @@ # from @(#)Makefile.inc 8.3 (Berkeley) 2/4/95 # $FreeBSD: src/lib/libc/stdlib/Makefile.inc,v 1.19.2.4 2001/10/02 11:15:38 ru Exp $ -# $DragonFly: src/lib/libc/stdlib/Makefile.inc,v 1.18 2007/10/19 20:16:43 swildner Exp $ +# $DragonFly: src/lib/libc/stdlib/Makefile.inc,v 1.19 2007/11/24 00:54:25 corecode Exp $ # 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 atoll.c bsearch.c calloc.c div.c \ exit.c getenv.c getopt.c getopt_long.c getsubopt.c hcreate.c heapsort.c \ - labs.c ldiv.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c \ + labs.c ldiv.c llabs.c malloc.c merge.c putenv.c qsort.c radixsort.c rand.c \ random.c reallocf.c realpath.c setenv.c strtod.c strtoimax.c strtol.c \ strtoll.c strtonum.c strtoq.c strtoul.c strtoull.c strtoumax.c \ strtouq.c system.c tdelete.c tfind.c tsearch.c twalk.c @@ -20,7 +20,7 @@ MISRCS+=abort.c abs.c atexit.c atof.c atoi.c atol.c atoll.c bsearch.c calloc.c d .if ${LIB} == "c" MAN+= abort.3 abs.3 alloca.3 atexit.3 atof.3 atoi.3 atol.3 bsearch.3 \ div.3 exit.3 getenv.3 getopt.3 getopt_long.3 getsubopt.3 hcreate.3 \ - labs.3 ldiv.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \ + labs.3 ldiv.3 llabs.3 malloc.3 memory.3 qsort.3 radixsort.3 rand.3 random.3 \ realpath.3 strtod.3 strtol.3 strtonum.3 strtoul.3 system.3 tsearch.3 MLINKS+=atol.3 atoll.3 diff --git a/lib/libc/stdlib/llabs.3 b/lib/libc/stdlib/llabs.3 new file mode 100644 index 0000000000..238802d420 --- /dev/null +++ b/lib/libc/stdlib/llabs.3 @@ -0,0 +1,63 @@ +.\" Copyright (c) 2001 Mike Barcroft +.\" 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. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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: src/lib/libc/stdlib/llabs.3,v 1.2 2001/11/21 16:19:50 ru Exp $ +.\" $DragonFly: src/lib/libc/stdlib/llabs.3,v 1.1 2007/11/24 00:54:25 corecode Exp $ +.\" +.Dd November 24, 2007 +.Dt LLABS 3 +.Os +.Sh NAME +.Nm llabs +.Nd return the absolute value of a long long integer +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In stdlib.h +.Ft "long long" +.Fn llabs "long long j" +.Sh DESCRIPTION +The +.Fn llabs +function returns the absolute value of the long long integer +.Fa j . +.Sh SEE ALSO +.Xr abs 3 , +.Xr fabs 3 , +.Xr hypot 3 , +.Xr imaxabs 3 , +.Xr labs 3 , +.Xr math 3 +.Sh STANDARDS +The +.Fn llabs +function conforms to +.St -isoC-99 . +.Sh HISTORY +The +.Fn llabs +function first appeared in +.Dx 1.11 . +.Sh BUGS +The absolute value of the most negative integer remains negative. diff --git a/lib/libc/stdlib/llabs.c b/lib/libc/stdlib/llabs.c new file mode 100644 index 0000000000..1e2dfa9993 --- /dev/null +++ b/lib/libc/stdlib/llabs.c @@ -0,0 +1,37 @@ +/*- + * Copyright (c) 2001 Mike Barcroft + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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: src/lib/libc/stdlib/llabs.c,v 1.1 2001/11/15 02:05:03 mike Exp $ + * $DragonFly: src/lib/libc/stdlib/llabs.c,v 1.1 2007/11/24 00:54:25 corecode Exp $ + * + */ + +#include + +long long +llabs(long long j) +{ + return (j < 0 ? -j : j); +} -- 2.11.4.GIT