# HG changeset patch # User Matti Hamalainen # Date 1352426359 -7200 # Node ID 3c3569894b2342ef984131764066b2d004ebaa8f # Parent 051ef70d01236e546318118b2f83a0fb2cb4adba Cosmetics. diff -r 051ef70d0123 -r 3c3569894b23 src/xs_support.c --- a/src/xs_support.c Fri Nov 09 03:59:02 2012 +0200 +++ b/src/xs_support.c Fri Nov 09 03:59:19 2012 +0200 @@ -180,21 +180,17 @@ /* Concatenate a given string up to given dest size or \n. * If size max is reached, change the end to "..." */ -void xs_pnstrcat(gchar *dest, size_t iSize, const gchar *str) +void xs_pnstrcat(gchar *dest, const size_t size, const gchar *str) { size_t i, n; const gchar *s; gchar *d; - d = dest; - i = 0; - while (*d && (i < iSize)) { - i++; - d++; - } + for (d = dest, i = 0; *d && i < size; i++, d++); s = str; - while (*s && (*s != '\n') && (i < iSize)) { + while (*s && *s != '\n' && i < size) + { *d = *s; d++; s++; @@ -203,16 +199,12 @@ *d = 0; - if (i >= iSize) { + if (i >= size) + { i--; d--; - n = 3; - while ((i > 0) && (n > 0)) { + for (n = 3; i > 0 && n > 0; d--, i--, n--) *d = '.'; - d--; - i--; - n--; - } } } @@ -256,7 +248,8 @@ static void xs_md5_bytereverse(guint8 *buf, guint l) { guint32 t; - do { + do + { t = (guint32) ((guint) buf[3] << 8 | buf[2]) << 16 | ((guint) buf[1] << 8 | buf[0]); *(guint32 *) buf = t; buf += sizeof(guint32); @@ -290,8 +283,7 @@ #define F2(x, y, z) F1(z, x, y) #define F3(x, y, z) (x ^ y ^ z) #define F4(x, y, z) (y ^ (x | ~z)) -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) +#define MD5STEP(f, w, x, y, z, data, s) ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) static void xs_md5_transform(guint32 buf[4], guint32 const in[16]) { @@ -393,11 +385,13 @@ t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ /* Handle any leading odd-sized chunks */ - if (t) { + if (t) + { guint8 *p = (guint8 *) ctx->in + t; t = 64 - t; - if (len < t) { + if (len < t) + { memcpy(p, buf, len); return; } @@ -409,7 +403,8 @@ } /* Process data in 64-byte chunks */ - while (len >= 64) { + while (len >= 64) + { memcpy(ctx->in, buf, 64); xs_md5_bytereverse(ctx->in, 16); xs_md5_transform(ctx->buf, (guint32 *) ctx->in); @@ -421,6 +416,7 @@ memcpy(ctx->in, buf, len); } + /* Final wrapup - pad to 64-byte boundary with the bit pattern * 1 0* (64-bit count of bits processed, MSB-first) */ @@ -441,7 +437,8 @@ count = 64 - 1 - count; /* Pad out to 56 mod 64 */ - if (count < 8) { + if (count < 8) + { /* Two lots of padding: Pad the first block to 64 bytes */ memset(p, 0, count); xs_md5_bytereverse(ctx->in, 16); @@ -449,7 +446,9 @@ /* Now fill the next block with 56 bytes */ memset(ctx->in, 0, 56); - } else { + } + else + { /* Pad block to 56 bytes */ memset(p, 0, count - 8); } diff -r 051ef70d0123 -r 3c3569894b23 src/xs_support.h --- a/src/xs_support.h Fri Nov 09 03:59:02 2012 +0200 +++ b/src/xs_support.h Fri Nov 09 03:59:19 2012 +0200 @@ -114,6 +114,7 @@ #define xs_ftell(a) ftell(a) #define xs_fseek(a,b,c) fseek(a,b,c) #endif + guint16 xs_fread_be16(XSFile *); guint32 xs_fread_be32(XSFile *); gboolean xs_fload_buffer(const gchar *filename,