Use q{To,From}BigEndian instead of hton* and ntoh*

These functions don't seem to be available as inline functions on win32

REVIEW: 115345
This commit is contained in:
Alex Richardson 2014-01-20 19:31:41 +01:00
parent bfea0e0e7c
commit a533bcd418
2 changed files with 11 additions and 10 deletions

View File

@ -26,7 +26,8 @@
*/ */
#include "pic_rw.h" #include "pic_rw.h"
#include <netinet/in.h>
#include <qendian.h>
#include <iostream> #include <iostream>
#include <qimage.h> #include <qimage.h>
#include <algorithm> #include <algorithm>
@ -47,10 +48,10 @@ bool picReadHeader(QIODevice *dev, PICHeader *hdr, bool peek)
result = dev->read((char *) hdr, HEADER_SIZE); result = dev->read((char *) hdr, HEADER_SIZE);
} }
hdr->magic = ntohl(hdr->magic); hdr->magic = qFromBigEndian(hdr->magic);
hdr->width = ntohs(hdr->width); hdr->width = qFromBigEndian(hdr->width);
hdr->height = ntohs(hdr->height); hdr->height = qFromBigEndian(hdr->height);
hdr->fields = ntohs(hdr->fields); hdr->fields = qFromBigEndian(hdr->fields);
if (hdr->magic != PIC_MAGIC_NUMBER || strncmp(hdr->id, "PICT", 4)) { if (hdr->magic != PIC_MAGIC_NUMBER || strncmp(hdr->id, "PICT", 4)) {
return false; return false;

View File

@ -26,9 +26,9 @@
*/ */
#include "pic_rw.h" #include "pic_rw.h"
#include <netinet/in.h>
#include <iostream> #include <iostream>
#include <qimage.h> #include <qimage.h>
#include <qendian.h>
/** /**
* Writes the PIC header info. * Writes the PIC header info.
@ -46,14 +46,14 @@ static bool writeHeader(QIODevice *dev, std::string msg, unsigned width, unsigne
unsigned count = 0; unsigned count = 0;
memset(&h, 0, sizeof(PICHeader)); memset(&h, 0, sizeof(PICHeader));
h.magic = htonl(PIC_MAGIC_NUMBER); h.magic = qToBigEndian<qint32>(PIC_MAGIC_NUMBER);
h.version = 3.71f; h.version = 3.71f;
strcpy(h.comment, msg.c_str()); strcpy(h.comment, msg.c_str());
strncpy(h.id, "PICT", 4); strncpy(h.id, "PICT", 4);
h.width = htons(width); h.width = qToBigEndian<qint16>(width);
h.height = htons(height); h.height = qToBigEndian<qint16>(height);
h.ratio = 1.0f; h.ratio = 1.0f;
h.fields = htons(BOTH); h.fields = qToBigEndian<qint16>(BOTH);
count = dev->write((const char *) & h, sizeof(PICHeader)); count = dev->write((const char *) & h, sizeof(PICHeader));
if (count != sizeof(PICHeader)) { if (count != sizeof(PICHeader)) {
return false; return false;