changeset 895:b6e069c9c000

Move stuff around a bit.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 09 Nov 2012 08:22:41 +0200
parents 4697c5bd7025
children 911401ea2145
files src/xs_support.c
diffstat 1 files changed, 107 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- 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)++;
+}
+
+