shithub: scc

Download patch

ref: 4c38694f5a5d742b1640a5d6add30ace501efa69
parent: 656c7dc0148256118fbc70cb19f9f8ce264ac542
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Wed Dec 6 18:16:21 EST 2017

[lib/c] Add abs(), labs() and llabs()

--- a/lib/c/include/stdlib.h
+++ b/lib/c/include/stdlib.h
@@ -66,4 +66,14 @@
 extern size_t mbstowcs(wchar_t * restrict pwcs, const char * restrict s, size_t n);
 extern size_t wcstombs(char * restrict s, const wchar_t * restrict pwcs, size_t n);
 
+#ifdef __USE_MACROS
+extern int __abs;
+extern long __labs;
+extern long long __llabs;
+
+#define abs(x)   (__abs = (x), (__abs) < 0 ? -__abs :  __abs)
+#define labs(x)  (__labs = (x), (__labs) < 0 ? -__labs :  __labs)
+#define llabs(x) (__llabs = (x), (__llabs) < 0 ? -__llabs :  __llabs)
+#endif
+
 #endif
--- a/lib/c/src/Makefile
+++ b/lib/c/src/Makefile
@@ -3,6 +3,7 @@
 include ../../../config.mk
 
 OBJ = bsearch.o \
+      abs.o __abs.o labs.o __labs.o llabs.o __labs.o \
       printf.o fprintf.o vfprintf.o \
       fgets.o gets.of fgetc.o fputc.o getchar.o putchar.o \
       fputs.o puts.o fread.o fwrite.o \
--- /dev/null
+++ b/lib/c/src/__abs.c
@@ -1,0 +1,5 @@
+
+#define __USE_MACROS
+#include <stdlib.h>
+
+int __abs;
--- /dev/null
+++ b/lib/c/src/__labs.c
@@ -1,0 +1,5 @@
+
+#define __USE_MACROS
+#include <stdlib.h>
+
+long __labs;
--- /dev/null
+++ b/lib/c/src/__llabs.c
@@ -1,0 +1,5 @@
+
+#define __USE_MACROS
+#include <stdlib.h>
+
+long long __llabs;
--- /dev/null
+++ b/lib/c/src/abs.c
@@ -1,0 +1,9 @@
+
+#include <stdlib.h>
+#undef abs
+
+int
+abs(int n)
+{
+	return (n < 0) ? -n : n;
+}
--- /dev/null
+++ b/lib/c/src/labs.c
@@ -1,0 +1,9 @@
+
+#include <stdlib.h>
+#undef labs
+
+long
+labs(long n)
+{
+	return (n < 0) ? -n : n;
+}
--- /dev/null
+++ b/lib/c/src/llabs.c
@@ -1,0 +1,9 @@
+
+#include <stdlib.h>
+#undef llabs
+
+long long
+llabs(long long n)
+{
+	return (n < 0) ? -n : n;
+}