diff --git a/ChangeLog b/ChangeLog index 94806d147ad..f8832b8a834 100755 --- a/ChangeLog +++ b/ChangeLog @@ -10820,4 +10820,8 @@ From Macs Neklyudov (2015-08-13). * fs/vfs/fs_poll.c: If we fail to setup the poll for any file descriptor, for any reason, set the POLLERR bit (2015-08-13). - + * libc/stdlib: Add support for div() to the C library. From + OrbitalFox (2015-08-14). + * libc/stdlib: Might as well add ldiv() and lldiv() to since + these are equivalent to div() with long and long long types, + respectively, instead of int (2015-08-14). diff --git a/include/stdlib.h b/include/stdlib.h index cd242227237..433b11dc9a8 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -105,6 +105,26 @@ struct div_s typedef struct div_s div_t; +/* Structure type returned by the ldiv() function. */ + +struct ldiv_s +{ + long quot; /* Quotient */ + long rem; /* Remainder */ +}; + +typedef struct ldiv_s ldiv_t; + +/* Structure type returned by the lldiv() function. */ + +struct lldiv_s +{ + long quot; /* Quotient */ + long rem; /* Remainder */ +}; + +typedef struct lldiv_s lldiv_t; + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -185,6 +205,10 @@ FAR void *calloc(size_t, size_t); int abs(int j); #ifdef CONFIG_CAN_PASS_STRUCTS div_t div(int numer, int denom); +ldiv_t ldiv(long numer, long denom); +#ifdef CONFIG_HAVE_LONG_LONG +lldiv_t lldiv(long long numer, long long denom); +#endif #endif long int labs(long int j); #ifdef CONFIG_HAVE_LONG_LONG diff --git a/libc/stdlib/Make.defs b/libc/stdlib/Make.defs index deffb5f62db..5f1b7a06a02 100644 --- a/libc/stdlib/Make.defs +++ b/libc/stdlib/Make.defs @@ -35,8 +35,9 @@ # Add the stdlib C files to the build -CSRCS += lib_abs.c lib_abort.c lib_div.c lib_imaxabs.c lib_itoa.c lib_labs.c -CSRCS += lib_llabs.c lib_rand.c lib_qsort.c +CSRCS += lib_abs.c lib_abort.c lib_div.c lib_ldiv.c lib_lldiv.c +CSRCS += lib_imaxabs.c lib_itoa.c lib_labs.c lib_llabs.c +CSRCS += lib_rand.c lib_qsort.c CSRCS += lib_strtol.c lib_strtoll.c lib_strtoul.c lib_strtoull.c CSRCS += lib_strtod.c lib_checkbase.c