From 53e204db3afa5ea95e87293a39801bf3eb4282eb Mon Sep 17 00:00:00 2001 From: Hugo Saint-Vignes Date: Tue, 4 Aug 2020 18:16:44 +0200 Subject: [PATCH] [liba] Add abs function for int Change-Id: Ic133ff2f34c7ff24ecbec69d5f31e447a72ae4fe --- ion/src/device/shared/usb/Makefile | 1 + liba/Makefile | 1 + liba/include/stdlib.h | 2 ++ liba/src/abs.c | 5 +++++ 4 files changed, 9 insertions(+) create mode 100644 liba/src/abs.c diff --git a/ion/src/device/shared/usb/Makefile b/ion/src/device/shared/usb/Makefile index 2e7ae45db..3db2b7d51 100644 --- a/ion/src/device/shared/usb/Makefile +++ b/ion/src/device/shared/usb/Makefile @@ -33,6 +33,7 @@ ion_device_usb_src += $(addprefix ion/src/device/shared/usb/stack/descriptor/, \ # DFU code +ion_device_dfu_src += liba/src/abs.c ion_device_dfu_src += liba/src/assert.c ion_device_dfu_src += liba/src/strlen.c ion_device_dfu_src += liba/src/strlcpy.c diff --git a/liba/Makefile b/liba/Makefile index 676fa88d0..3639ceb91 100644 --- a/liba/Makefile +++ b/liba/Makefile @@ -3,6 +3,7 @@ SFLAGS += -Iliba/include liba_src += $(addprefix liba/src/, \ armv7m/setjmp.s \ armv7m/longjmp.s \ + abs.c \ assert.c \ bzero.c \ ctype.c \ diff --git a/liba/include/stdlib.h b/liba/include/stdlib.h index 6cf0a9654..6c27b3d6e 100644 --- a/liba/include/stdlib.h +++ b/liba/include/stdlib.h @@ -13,6 +13,8 @@ void * calloc(size_t count, size_t size); void abort(void) __attribute__((noreturn)); +int abs(int n); + LIBA_END_DECLS #endif diff --git a/liba/src/abs.c b/liba/src/abs.c new file mode 100644 index 000000000..8d0efabdc --- /dev/null +++ b/liba/src/abs.c @@ -0,0 +1,5 @@ +#include + +int abs(int n) { + return n < 0 ? -n : n; +} \ No newline at end of file