diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-01-14 04:40:03 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-01-14 04:40:03 +0100 |
| commit | a2dfbb3368ce0e998f774dd294383772651d1302 (patch) | |
| tree | 094dbc3206297d3b3b0d090daff426ce66ea45f7 /src/util | |
| parent | Rename to blind (diff) | |
| download | blind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.gz blind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.bz2 blind-a2dfbb3368ce0e998f774dd294383772651d1302.tar.xz | |
Fix errors, blind-{to,from}-{video,image} works
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/endian.h | 43 | ||||
| -rw-r--r-- | src/util/to.h | 8 |
2 files changed, 47 insertions, 4 deletions
diff --git a/src/util/endian.h b/src/util/endian.h new file mode 100644 index 0000000..e6805b1 --- /dev/null +++ b/src/util/endian.h @@ -0,0 +1,43 @@ +/* See LICENSE file for copyright and license details. */ +#include <stdint.h> + +#if defined(HAVE_ENDIAN_H) +# include <endian.h> +#elif defined(HAVE_SYS_ENDIAN_H) +# include <sys/endian.h> +#endif + +#if !defined(HAVE_ENDIAN_H) && !defined(HAVE_SYS_ENDIAN_H) + +# if !defined(htole16) +# define htole16 blind_htole16 +static inline uint16_t +blind_htole16(uint16_t h) +{ + union { + unsigned char bytes[2]; + uint16_t value; + } d; + d.bytes[0] = h; + d.bytes[1] = h >> 8; + return d.value; +} +# endif + +# if !defined(le16toh) +# if defined(letoh16) +# define le16toh letoh16 +# else +# define le16toh blind_le16toh +static inline uint16_t +blind_le16toh(uint16_t le) +{ + unsigned char *bytes = (unsigned char *)≤ + return ((uint16_t)(bytes[1]) << 8) | (uint16_t)(bytes[0]); +} +# endif +# endif + +#elif defined(HAVE_OPENBSD_ENDIAN) +# define le16toh letoh16 +#endif diff --git a/src/util/to.h b/src/util/to.h index 7bb08c7..c927d57 100644 --- a/src/util/to.h +++ b/src/util/to.h @@ -29,7 +29,7 @@ DEF_STR_TO_INT(toi, int, tolli, long long int, "i") en##FNAME##_flag(int status, int flag, const char *s, TYPE min, TYPE max)\ {\ TYPE ret = 0;\ - if (!FNAME(s, min, max, &ret))\ + if (FNAME(s, min, max, &ret))\ enprintf(status,\ "argument of -%c must be an integer in [%"PRI", %"PRI"]\n",\ flag, min, max);\ @@ -46,7 +46,7 @@ DEF_STR_TO_INT(toi, int, tolli, long long int, "i") en##FNAME##_arg(int status, const char *name, const char *s, TYPE min, TYPE max)\ {\ TYPE ret = 0;\ - if (!FNAME(s, min, max, &ret))\ + if (FNAME(s, min, max, &ret))\ enprintf(status,\ "%s must be an integer in [%"PRI", %"PRI"]\n",\ name, min, max);\ @@ -104,7 +104,7 @@ DEF_STR_TO_INT(toi, int, "i") en##FNAME##_flag(int status, int flag, const char *s)\ {\ TYPE ret = 0;\ - if (!FNAME(s, &ret))\ + if (FNAME(s, &ret))\ enprintf(status, "argument of -%c must be floating-point value\n", flag);\ return ret;\ }\ @@ -119,7 +119,7 @@ DEF_STR_TO_INT(toi, int, "i") en##FNAME##_arg(int status, const char *name, const char *s)\ {\ TYPE ret = 0;\ - if (!FNAME(s, &ret))\ + if (FNAME(s, &ret))\ enprintf(status, "%s must be floating-point value\n", name);\ return ret;\ }\ |
