diff --git a/libc/include/stdlib.h b/libc/include/stdlib.h index 401d9a011..3e3be6fbf 100644 --- a/libc/include/stdlib.h +++ b/libc/include/stdlib.h @@ -33,6 +33,7 @@ void dtostr(double val, int style, int preci, char *buf); long atol(const char *str); int atoi(const char *str); +int abs(int x); /* Returned by `div'. */ typedef struct diff --git a/libc/misc/Makefile b/libc/misc/Makefile index 91aa98054..596f7deae 100644 --- a/libc/misc/Makefile +++ b/libc/misc/Makefile @@ -6,6 +6,7 @@ LIB ?= out.a include $(TOPDIR)/libc/$(COMPILER).inc OBJS = \ + abs.o \ aliases.o \ atexit.o \ atof.o \ diff --git a/libc/misc/abs.c b/libc/misc/abs.c new file mode 100644 index 000000000..76e9486b6 --- /dev/null +++ b/libc/misc/abs.c @@ -0,0 +1,6 @@ +#include + +int abs(int x) +{ + return x < 0? -x : x; +}