aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--gen/bits/intconf.c37
-rw-r--r--src/arpa/inet/htonl.c6
-rw-r--r--src/arpa/inet/ntohl.c6
3 files changed, 33 insertions, 16 deletions
diff --git a/gen/bits/intconf.c b/gen/bits/intconf.c
index 361dd16..4fe45fd 100644
--- a/gen/bits/intconf.c
+++ b/gen/bits/intconf.c
@@ -173,17 +173,34 @@ static char* byteorder_16(void)
static char* byteorder_32(void)
{
static char buf[32 / 4 + 1];
- union
- {
- int all;
- struct
+ if (8 * sizeof(int) == 32)
{
- char a; char b; char c; char d;
- };
- } test = { .all = 0x01020304 };
+ union
+ {
+ int all;
+ struct
+ {
+ char a; char b; char c; char d;
+ };
+ } test = { .all = 0x01020304 };
- sprintf(buf, "%02i%02i%02i%02i",
- test.a, test.b, test.c, test.d);
+ sprintf(buf, "%02i%02i%02i%02i",
+ test.a, test.b, test.c, test.d);
+ }
+ else
+ {
+ union
+ {
+ long int all;
+ struct
+ {
+ char a; char b; char c; char d;
+ };
+ } test = { .all = 0x01020304L };
+
+ sprintf(buf, "%02i%02i%02i%02i",
+ test.a, test.b, test.c, test.d);
+ }
return buf;
}
@@ -245,7 +262,7 @@ int main(int argc, char* argv[])
/* Print byte orders. */
r |= printf("INT16_BYTEORDER 0x%s\n", byteorder_16());
- r |= printf("INT32_BYTEORDER 0x%s\n", byteorder_32());
+ r |= printf("INT32_BYTEORDER 0x%sL\n", byteorder_32());
r |= printf("INT64_BYTEORDER 0x%sLL\n", byteorder_64());
/* Print the intrinsic type for specific numbers of bits. */
diff --git a/src/arpa/inet/htonl.c b/src/arpa/inet/htonl.c
index 8422fdc..233cc06 100644
--- a/src/arpa/inet/htonl.c
+++ b/src/arpa/inet/htonl.c
@@ -33,11 +33,11 @@
*/
uint32_t _htonl(uint32_t value)
{
-#if __INT32_BYTEORDER == 0x01020304
+#if __INT32_BYTEORDER == 0x01020304L
return value;
-#elif __INT32_BYTEORDER == 0x04030201
+#elif __INT32_BYTEORDER == 0x04030201L
return (value >> 24) | ((value & 0xFF0000) >> 8) | ((value & 0x00FF00) << 8) | (value << 24);
-#elif __INT32_BYTEORDER == 0x02010403
+#elif __INT32_BYTEORDER == 0x02010403L
return (value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
#else
char rc[4];
diff --git a/src/arpa/inet/ntohl.c b/src/arpa/inet/ntohl.c
index 7111c28..b9c3757 100644
--- a/src/arpa/inet/ntohl.c
+++ b/src/arpa/inet/ntohl.c
@@ -33,11 +33,11 @@
*/
uint32_t _ntohl(uint32_t value)
{
-#if __INT32_BYTEORDER == 0x01020304
+#if __INT32_BYTEORDER == 0x01020304L
return value;
-#elif __INT32_BYTEORDER == 0x04030201
+#elif __INT32_BYTEORDER == 0x04030201L
return (value >> 24) | ((value & 0xFF0000) >> 8) | ((value & 0x00FF00) << 8) | (value << 24);
-#elif __INT32_BYTEORDER == 0x02010403
+#elif __INT32_BYTEORDER == 0x02010403L
return (value & 0xFF00FF00) >> 8) | ((value & 0x00FF00FF) << 8);
#else
unsigned char* v = (unsigned char*)&value;