diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2017-02-15 22:32:45 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2017-02-15 22:32:45 +0200 |
| commit | d94ae26d161be87c58906dac10519e8156469923 (patch) | |
| tree | 8d2dfad44d245acbf02598fad0cee0ec60305e70 /src/stream.c | |
| parent | e41108fe4f40113f51e7b873f5165ebaf2b085d1 (diff) | |
| download | mqtt-d94ae26d161be87c58906dac10519e8156469923.tar.gz mqtt-d94ae26d161be87c58906dac10519e8156469923.zip | |
Home-made 16 bit big endian reading and writing in stream.c
Diffstat (limited to 'src/stream.c')
| -rw-r--r-- | src/stream.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/stream.c b/src/stream.c index 97a8a2d..e7dd7f7 100644 --- a/src/stream.c +++ b/src/stream.c @@ -6,9 +6,6 @@ #include <assert.h> #include <errno.h> -/* htons, ntohs */ -#include <arpa/inet.h> - #define STREAM_CHECK_OP(stream, op) \ do { if ((stream->ops->op) == NULL) \ { \ @@ -42,10 +39,11 @@ int64_t StreamRead(void *ptr, size_t size, Stream *stream) int64_t StreamReadUint16Be(uint16_t *v, Stream *stream) { + unsigned char data[2]; STREAM_CHECK_OP(stream, read); - if (StreamRead(v, 2, stream) != 2) + if (StreamRead(data, 2, stream) != 2) return -1; - *v = ntohs(*v); + *v = (data[1] << 0) | (data[0] << 1); return 2; } @@ -61,8 +59,10 @@ int64_t StreamWrite(const void *ptr, size_t size, Stream *stream) int64_t StreamWriteUint16Be(uint16_t v, Stream *stream) { - v = htons(v); - return StreamWrite(&v, sizeof(v), stream); + unsigned char data[2]; + data[0] = v >> 8; + data[1] = v; + return StreamWrite(data, sizeof(data), stream); } int StreamSeek(Stream *stream, int64_t offset, int whence) |
