summaryrefslogtreecommitdiffstats
path: root/libc/stdlib
diff options
context:
space:
mode:
authorShilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>2017-05-26 13:58:57 +0530
committerStewart Smith <stewart@linux.vnet.ibm.com>2017-05-31 16:58:05 +1000
commit41bb3e7cd4eda5371d7cd0310e31357550279ccd (patch)
tree62e6d7dfea5e419444162a8dee2e9abe72bb7776 /libc/stdlib
parent1d4a0a4374f69c890b64f5463930775d94139ded (diff)
downloadtalos-skiboot-41bb3e7cd4eda5371d7cd0310e31357550279ccd.tar.gz
talos-skiboot-41bb3e7cd4eda5371d7cd0310e31357550279ccd.zip
libc: Add labs() to stdlib
Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com> Acked-by: Balbir Singh <bsingharora@gmail.com> Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'libc/stdlib')
-rw-r--r--libc/stdlib/Makefile.inc2
-rw-r--r--libc/stdlib/labs.c25
2 files changed, 26 insertions, 1 deletions
diff --git a/libc/stdlib/Makefile.inc b/libc/stdlib/Makefile.inc
index 6d1123e0..22417dfb 100644
--- a/libc/stdlib/Makefile.inc
+++ b/libc/stdlib/Makefile.inc
@@ -13,7 +13,7 @@
SUBDIRS += $(LIBCDIR)/stdlib
STDLIB_OBJS = error.o atoi.o atol.o strtol.o strtoul.o \
- rand.o
+ rand.o labs.o
STDLIB = $(LIBCDIR)/stdlib/built-in.o
$(STDLIB): $(STDLIB_OBJS:%=$(LIBCDIR)/stdlib/%)
diff --git a/libc/stdlib/labs.c b/libc/stdlib/labs.c
new file mode 100644
index 00000000..9b68bb27
--- /dev/null
+++ b/libc/stdlib/labs.c
@@ -0,0 +1,25 @@
+/******************************************************************************
+ * Copyright (c) 2017 IBM Corporation
+ * All rights reserved.
+ * This program and the accompanying materials
+ * are made available under the terms of the BSD License
+ * which accompanies this distribution, and is available at
+ * http://www.opensource.org/licenses/bsd-license.php
+ *
+ * Contributors:
+ * IBM Corporation - initial implementation
+ *****************************************************************************/
+
+#include <stdlib.h>
+
+/**
+ * labs() - Computes the absolute value of long integer
+ * @n: long integer number
+ *
+ * Returns the absolute value of the long integer argument
+ */
+
+long int labs(long int n)
+{
+ return (n > 0) ? n : -n;
+}
OpenPOWER on IntegriCloud