# HG changeset patch # User Matti Hamalainen # Date 1352442161 -7200 # Node ID b6e069c9c000260f2cd8008d6b3c3fbc705a395e # Parent 4697c5bd70251c6044e4cf7edd6134c5297dab0c Move stuff around a bit. diff -r 4697c5bd7025 -r b6e069c9c000 src/xs_support.c --- a/src/xs_support.c Fri Nov 09 08:20:55 2012 +0200 +++ b/src/xs_support.c Fri Nov 09 08:22:41 2012 +0200 @@ -194,110 +194,6 @@ } -/* Copy a given string over in *result. - */ -gint xs_pstrcpy(gchar **result, const gchar *str) -{ - /* Check the string pointers */ - if (!result || !str) - return -1; - - /* Allocate memory for destination */ - g_free(*result); - - *result = (gchar *) g_malloc(strlen(str) + 1); - if (!*result) - return -2; - - /* Copy to the destination */ - strcpy(*result, str); - - return 0; -} - - -/* Concatenates a given string into string pointed by *result. - */ -gint xs_pstrcat(gchar **result, const gchar *str) -{ - /* Check the string pointers */ - if (!result || !str) - return -1; - - if (*result != NULL) - { - *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1); - if (*result == NULL) - return -1; - strcat(*result, str); - } - else - { - *result = (gchar *) g_malloc(strlen(str) + 1); - if (*result == NULL) - return -1; - strcpy(*result, str); - } - - return 0; -} - - -/* 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, const size_t size, const gchar *str) -{ - size_t i, n; - const gchar *s; - gchar *d; - - for (d = dest, i = 0; *d && i < size; i++, d++); - - s = str; - while (*s && *s != '\n' && i < size) - { - *d = *s; - d++; - s++; - i++; - } - - *d = 0; - - if (i >= size) - { - i--; - d--; - for (n = 3; i > 0 && n > 0; d--, i--, n--) - *d = '.'; - } -} - - -/* Locate character in string - */ -void xs_findnext(const gchar *str, size_t *pos) -{ - while (str[*pos] && isspace(str[*pos])) - (*pos)++; -} - - -void xs_findeol(const gchar *str, size_t *pos) -{ - while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r')) - (*pos)++; -} - - -void xs_findnum(const gchar *str, size_t *pos) -{ - while (str[*pos] && isdigit(str[*pos])) - (*pos)++; -} - - /* * MD5 implementation, modified for XMMS-SID from * Colin Plumb's implementation by Matti 'ccr' Hämäläinen. @@ -527,5 +423,111 @@ xs_md5_transform(ctx->buf, (guint32 *) ctx->in); xs_md5_bytereverse((guint8 *) ctx->buf, 4); memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */ + memset(ctx, 0, sizeof(ctx)); +} + + +/* Copy a given string over in *result. + */ +gint xs_pstrcpy(gchar **result, const gchar *str) +{ + /* Check the string pointers */ + if (!result || !str) + return -1; + + /* Allocate memory for destination */ + g_free(*result); + + *result = (gchar *) g_malloc(strlen(str) + 1); + if (!*result) + return -2; + + /* Copy to the destination */ + strcpy(*result, str); + + return 0; +} + + +/* Concatenates a given string into string pointed by *result. + */ +gint xs_pstrcat(gchar **result, const gchar *str) +{ + /* Check the string pointers */ + if (!result || !str) + return -1; + + if (*result != NULL) + { + *result = (gchar *) g_realloc(*result, strlen(*result) + strlen(str) + 1); + if (*result == NULL) + return -1; + strcat(*result, str); + } + else + { + *result = (gchar *) g_malloc(strlen(str) + 1); + if (*result == NULL) + return -1; + strcpy(*result, str); + } + + return 0; } + + +/* 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, const size_t size, const gchar *str) +{ + size_t i, n; + const gchar *s; + gchar *d; + + for (d = dest, i = 0; *d && i < size; i++, d++); + + s = str; + while (*s && *s != '\n' && i < size) + { + *d = *s; + d++; + s++; + i++; + } + + *d = 0; + + if (i >= size) + { + i--; + d--; + for (n = 3; i > 0 && n > 0; d--, i--, n--) + *d = '.'; + } +} + + +/* Locate character in string + */ +void xs_findnext(const gchar *str, size_t *pos) +{ + while (str[*pos] && isspace(str[*pos])) + (*pos)++; +} + + +void xs_findeol(const gchar *str, size_t *pos) +{ + while (str[*pos] && (str[*pos] != '\n') && (str[*pos] != '\r')) + (*pos)++; +} + + +void xs_findnum(const gchar *str, size_t *pos) +{ + while (str[*pos] && isdigit(str[*pos])) + (*pos)++; +} + +