Mercurial > hg > toybox
changeset 1275:6f18a0845db3 draft
Use compiler built-in macros to determine if argument parsing can use double or float for FLOAT arguments. (I.E. whether double fits in a long's memory.) Check in a way that the macros not being defined just gives us the shorter one.
author | Rob Landley <rob@landley.net> |
---|---|
date | Tue, 06 May 2014 06:14:20 -0500 |
parents | c47218ccbfdf |
children | d48bdc1cb017 |
files | lib/pending.h lib/portability.h |
diffstat | 2 files changed, 10 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/pending.h Mon May 05 21:20:11 2014 -0500 +++ b/lib/pending.h Tue May 06 06:14:20 2014 -0500 @@ -1,13 +1,5 @@ // pending.h - header for pending.c -// Unfortunately, sizeof() doesn't work in a preprocessor test. TODO. - -//#if sizeof(double) <= sizeof(long) -//typedef double FLOAT; -//#else -typedef float FLOAT; -//#endif - // password.c #define MAX_SALT_LEN 20 //3 for id, 16 for key, 1 for '\0' #define SYS_FIRST_ID 100
--- a/lib/portability.h Mon May 05 21:20:11 2014 -0500 +++ b/lib/portability.h Tue May 06 06:14:20 2014 -0500 @@ -148,7 +148,8 @@ #define SWAP_LE64(x) (x) #endif -#if defined(__APPLE__) || defined(__ANDROID__) || (defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 10) +#if defined(__APPLE__) || defined(__ANDROID__) \ + || (defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 10) ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); ssize_t getline(char **lineptr, size_t *n, FILE *stream); #endif @@ -163,3 +164,11 @@ #ifndef O_NOFOLLOW #define O_NOFOLLOW 0 #endif + +#if defined(__SIZEOF_DOUBLE__) && defined(__SIZEOF_LONG__) \ + && __SIZEOF_DOUBLE__ <= __SIZEOF_LONG__ +typedef double FLOAT; +#else +typedef float FLOAT; +#endif +