diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2012-06-20 09:00:33 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2012-06-20 09:10:28 -0400 |
commit | 7f5851d906449063c6cc653e7967549e861a2fea (patch) | |
tree | d69483f350637411f556eb18f94e50c2ba0b0296 /hex.c | |
parent | 6f34d11aae04a9a9d47c3a4f6af3d5a55774b53e (diff) | |
download | gpsd-7f5851d906449063c6cc653e7967549e861a2fea.tar.gz |
Split gpsd_hexdump() so AIS dumping will be invertible.
Diffstat (limited to 'hex.c')
-rw-r--r-- | hex.c | 47 |
1 files changed, 26 insertions, 21 deletions
@@ -8,7 +8,7 @@ #include "gpsd.h" -const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) +const char /*@ observer @*/ *gpsd_packetdump(char *binbuf, size_t binbuflen) { char *cp; bool printable = true; @@ -19,31 +19,36 @@ const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) printable = false; if (printable) return binbuf; - else { - static char hexbuf[MAX_PACKET_LENGTH * 2 + 1]; + else + return gpsd_hexdump(binbuf, binbuflen); +} + +const char /*@ observer @*/ *gpsd_hexdump(char *binbuf, size_t binbuflen) +{ + /* FIXME: this isn't thead-safe! */ + static char hexbuf[MAX_PACKET_LENGTH * 2 + 1]; #ifndef SQUELCH_ENABLE - size_t i, j = 0; - size_t len = - (size_t) ((binbuflen > - MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen); - const char *ibuf = (const char *)binbuf; - const char *hexchar = "0123456789abcdef"; + size_t i, j = 0; + size_t len = + (size_t) ((binbuflen > + MAX_PACKET_LENGTH) ? MAX_PACKET_LENGTH : binbuflen); + const char *ibuf = (const char *)binbuf; + const char *hexchar = "0123456789abcdef"; - if (NULL == binbuf || 0 == binbuflen) - return ""; + if (NULL == binbuf || 0 == binbuflen) + return ""; - /*@ -shiftimplementation @*/ - for (i = 0; i < len; i++) { - hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4]; - hexbuf[j++] = hexchar[ibuf[i] & 0x0f]; - } - /*@ +shiftimplementation @*/ - hexbuf[j] = '\0'; + /*@ -shiftimplementation @*/ + for (i = 0; i < len; i++) { + hexbuf[j++] = hexchar[(ibuf[i] & 0xf0) >> 4]; + hexbuf[j++] = hexchar[ibuf[i] & 0x0f]; + } + /*@ +shiftimplementation @*/ + hexbuf[j] = '\0'; #else /* SQUELCH defined */ - hexbuf[0] = '\0'; + hexbuf[0] = '\0'; #endif /* SQUELCH_ENABLE */ - return hexbuf; - } + return hexbuf; } /*@ +charint -shiftimplementation @*/ |