#if defined _WIN32 && defined USERLEVEL
int Util_TokenHasAdminPriv(HANDLE token);
#endif
+
Bool Util_Data2Buffer(char *buf, size_t bufSize, const void *data0,
size_t dataSize);
+Bool Util_Data2BufferEx(char *buf, size_t bufSize, const void *data0,
+ size_t dataSize, char sep);
+
char *Util_GetCanonicalPath(const char *path);
#ifdef _WIN32
char *Util_CompatGetCanonicalPath(const char *path);
*
* Util_Data2Buffer --
*
- * Format binary data for printing
+ * Format binary data for printing.
+ * Uses space as byte separator.
*
* Results:
- * TRUE if all data fits into buffer, FALSE otherwise.
+ * TRUE if all data fits into buffer, FALSE otherwise.
*
* Side effects:
- * None
+ * None
*
*----------------------------------------------------------------------
*/
const void *data0, // IN
size_t dataSize) // IN
{
- size_t n;
+ return Util_Data2BufferEx(buf, bufSize, data0, dataSize, ' ');
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * Util_Data2BufferEx --
+ *
+ * Format binary data for printing.
+ * Uses custom byte separator. None if set to '\0'.
+ *
+ * Results:
+ * TRUE if all data fits into buffer, FALSE otherwise.
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+Bool
+Util_Data2BufferEx(char *buf, // OUT
+ size_t bufSize, // IN
+ const void *data0, // IN
+ size_t dataSize, // IN
+ char sep) // IN
+{
+ size_t n; /* Chars to process from data0. */
+ const Bool useSeparator = sep != 0;
+
+ /* Number of processed chars that will fit in buf and leave space for trailing NUL. */
+ const size_t outChars = useSeparator ? bufSize / 3 : (bufSize - 1) / 2;
/* At least 1 byte (for NUL) must be available. */
if (!bufSize) {
return FALSE;
}
- bufSize = bufSize / 3;
- n = MIN(dataSize, bufSize);
+ n = MIN(dataSize, outChars);
if (n != 0) {
const uint8 *data = data0;
*buf++ = digits[*data >> 4];
*buf++ = digits[*data & 0xF];
- *buf++ = ' ';
+ if (useSeparator) {
+ *buf++ = sep;
+ }
data++;
n--;
}
- buf--;
+ if (useSeparator) {
+ buf--; /* Overwrite the last separator with NUL. */
+ }
}
*buf = 0;
- return dataSize <= bufSize;
+ return dataSize <= outChars;
}