From 378610259f4d40b8bd959c12e929ba7c93db2f2c Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 21 Jul 2003 20:20:04 +0000 Subject: [PATCH] llabs(3) for C99 --- src/lib/libc/stdlib/labs.3 | 20 ++++++++++++----- src/lib/libc/stdlib/llabs.c | 45 +++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 src/lib/libc/stdlib/llabs.c diff --git a/src/lib/libc/stdlib/labs.3 b/src/lib/libc/stdlib/labs.3 index d00c3072..742f3eed 100644 --- a/src/lib/libc/stdlib/labs.3 +++ b/src/lib/libc/stdlib/labs.3 @@ -29,22 +29,28 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: labs.3,v 1.6 2003/06/02 20:18:37 millert Exp $ +.\" $OpenBSD: labs.3,v 1.7 2003/07/21 20:20:04 millert Exp $ .\" -.Dd June 29, 1991 +.Dd May 14, 2003 .Dt LABS 3 .Os .Sh NAME -.Nm labs +.Nm labs, llabs .Nd return the absolute value of a long integer .Sh SYNOPSIS .Fd #include .Ft long -.Fn labs "long j" +.Fn labs "long i" +.Ft long long +.Fn llabs "long long j" .Sh DESCRIPTION The .Fn labs function returns the absolute value of the long integer +.Fa i . +The +.Fn llabs +function returns the absolute value of the long long integer .Fa j . .Sh SEE ALSO .Xr abs 3 , @@ -54,7 +60,9 @@ function returns the absolute value of the long integer .Sh STANDARDS The .Fn labs -function conforms to -.St -ansiC . +and +.Fn llabs +functions conform to +.St -ansiC-99 . .Sh BUGS The absolute value of the most negative integer remains negative. diff --git a/src/lib/libc/stdlib/llabs.c b/src/lib/libc/stdlib/llabs.c new file mode 100644 index 00000000..9611b5ae --- /dev/null +++ b/src/lib/libc/stdlib/llabs.c @@ -0,0 +1,45 @@ +/* $OpenBSD: llabs.c,v 1.1 2003/07/21 20:20:04 millert Exp $ */ + +/*- + * Copyright (c) 1990 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: llabs.c,v 1.1 2003/07/21 20:20:04 millert Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include + +long long llabs(long long j) +{ + return (j < 0 ? -j : j); +}