diff options
author | sin <sin@2f30.org> | 2015-11-17 16:52:18 +0000 |
---|---|---|
committer | sin <sin@2f30.org> | 2015-11-17 16:59:19 +0000 |
commit | e706c3f9a51e5b2e2b05b70fca71f870b7fc35f9 (patch) | |
tree | 9338b2dfa3a571403f5c7f49882bc284bce3b92d | |
parent | ed7b08b8d22e0f039f93f70dd23280289edb27e5 (diff) |
Avoid using the non-portable endian.h conversion functions
Use the arpa/inet.h conversion functions which are standardized
in POSIX.
-rw-r--r-- | ff2png.c | 10 | ||||
-rw-r--r-- | png2ff.c | 10 |
2 files changed, 10 insertions, 10 deletions
@@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#define _BSD_SOURCE -#include <endian.h> +#include <arpa/inet.h> + #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -34,8 +34,8 @@ main(int argc, char *argv[]) fprintf(stderr, "invalid magic in header\n"); return 1; } - width = be32toh(*((uint32_t *)(hdr + 8))); - height = be32toh(*((uint32_t *)(hdr + 12))); + width = ntohl(*((uint32_t *)(hdr + 8))); + height = ntohl(*((uint32_t *)(hdr + 12))); /* load png */ png_struct_p = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); @@ -65,7 +65,7 @@ main(int argc, char *argv[]) return 1; } /* ((2^16-1) / 255) == 257 */ - png_row[j] = (uint8_t)(be16toh(tmp16) / 257); + png_row[j] = (uint8_t)(ntohs(tmp16) / 257); } png_write_row(png_struct_p, png_row); } @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#define _BSD_SOURCE -#include <endian.h> +#include <arpa/inet.h> + #include <stdint.h> #include <stdio.h> #include <stdlib.h> @@ -43,9 +43,9 @@ main(int argc, char *argv[]) /* write header */ fprintf(stdout, "farbfeld"); - tmp32 = htobe32(width); + tmp32 = htonl(width); fwrite(&tmp32, sizeof(uint32_t), 1, stdout); - tmp32 = htobe32(height); + tmp32 = htonl(height); fwrite(&tmp32, sizeof(uint32_t), 1, stdout); /* write data */ @@ -53,7 +53,7 @@ main(int argc, char *argv[]) for (r = 0; r < height; ++r) { for (i = 0; i < png_row_len; i++) { /* ((2^16-1) / 255) == 257 */ - tmp16 = htobe16(257 * png_row_p[r][i]); + tmp16 = htons(257 * png_row_p[r][i]); fwrite(&tmp16, sizeof(uint16_t), 1, stdout); } } |