Mercurial > hg > xmms-sid
comparison src/xs_support.c @ 38:dec37e16136e
Minor changes
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 19 Jun 2003 20:48:04 +0000 |
parents | 4bb09e405eab |
children | 1788f4ce6a44 |
comparison
equal
deleted
inserted
replaced
37:5379205b74dd | 38:dec37e16136e |
---|---|
26 #include <ctype.h> | 26 #include <ctype.h> |
27 | 27 |
28 /* | 28 /* |
29 * Utility routines | 29 * Utility routines |
30 */ | 30 */ |
31 int xs_strcalloc(gchar **result, const gchar *str) | 31 gint xs_strcalloc(gchar **ppcResult, const gchar *pcStr) |
32 { | 32 { |
33 /* Check the string pointers */ | 33 assert(ppcResult); |
34 if ((result == NULL) || (str == NULL)) | 34 assert(pcStr); |
35 return -1; | 35 |
36 /* Allocate memory for destination */ | |
37 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(pcStr) + 1); | |
38 if (*ppResult == NULL) return -1; | |
36 | 39 |
37 /* Allocate memory for destination */ | 40 /* Copy to the destination */ |
38 *result = (gchar *) g_realloc(*result, strlen(str) + 1); | 41 strcpy(*ppcResult, pcStr); |
39 | 42 |
40 if (*result == NULL) return -2; | 43 return 0; |
41 | |
42 /* Copy to the destination */ | |
43 strcpy(*result, str); | |
44 | |
45 return 0; | |
46 } | 44 } |
47 | 45 |
48 | 46 |
49 int xs_strcat(gchar **ppcResult, const gchar *pcStr) | 47 int xs_strcat(gchar **ppcResult, const gchar *pcStr) |
50 { | 48 { |
51 int ilen; | 49 assert(ppcResult); |
50 assert(pcStr); | |
51 | |
52 /* Re-allocate memory for destination */ | |
53 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + strlen(pcStr) + 1); | |
54 if (*ppcResult == NULL) return -1; | |
52 | 55 |
53 /* Check the pcString pointers */ | 56 /* Cat to the destination */ |
54 if ((ppcResult == NULL) || (pcStr == NULL)) | 57 strcat(*ppcResult, pcStr); |
55 return -1; | |
56 | 58 |
57 /* Get length of the pcString to be catted */ | 59 return 0; |
58 ilen = strlen(pcStr); | |
59 | |
60 /* Re-allocate memory for destination */ | |
61 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + ilen + 1); | |
62 | |
63 if (*ppcResult == NULL) return -2; | |
64 | |
65 /* Cat to the destination */ | |
66 strcat(*ppcResult, pcStr); | |
67 | |
68 return 0; | |
69 } | 60 } |
70 | 61 |
71 | 62 |
72 int xs_strcpy(gchar **ppcResult, gint *j, const gchar *pcStr) | 63 int xs_strpcat(gchar **ppcResult, gint *j, const gchar *pcStr) |
73 { | 64 { |
74 int ilen; | 65 int iLen; |
75 | 66 |
76 /* Check the pcString pointers */ | 67 assert(ppcResult); |
77 if ((ppcResult == NULL) || (pcStr == NULL) || (j == NULL)) | 68 assert(pcStr); |
78 return -1; | 69 assert(j); |
70 | |
71 /* Get length of the pcString to be catted */ | |
72 iLen = strlen(pcStr); | |
73 (*j) += iLen; | |
79 | 74 |
80 /* Get length of the pcString to be catted */ | 75 /* Re-allocate memory for destination */ |
81 (*j) += ilen = strlen(pcStr); | 76 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + iLen + 1); |
77 if (*ppcResult == NULL) return -1; | |
82 | 78 |
83 /* Re-allocate memory for destination */ | 79 /* Cat to the destination */ |
84 *ppcResult = (gchar *) g_realloc(*ppcResult, strlen(*ppcResult) + ilen + 1); | 80 strcat(*ppcResult, pcStr); |
85 | 81 |
86 if (*ppcResult == NULL) return -2; | 82 return 0; |
87 | |
88 /* Cat to the destination */ | |
89 strcat(*ppcResult, pcStr); | |
90 | |
91 return 0; | |
92 } | 83 } |
93 | 84 |
94 | 85 |
95 inline void xs_findnext(gchar *pcStr, gint *piPos) | 86 inline void xs_findnext(gchar *pcStr, gint *piPos) |
96 { | 87 { |