Mercurial > hg > xmms-sid
annotate src/xs_support.c @ 218:57231fe14369
Minor fixes
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 15 Dec 2004 11:23:02 +0000 |
parents | 575686094eb1 |
children | df4cb5115322 |
rev | line source |
---|---|
4 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Miscellaneous support functions | |
5 | |
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org> | |
7 | |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 */ | |
214 | 22 #include "xmms-sid.h" |
49
3518ca5c8b0f
Support for compile-time big/little-endian optimizations in audio output
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
23 #include "xs_support.h" |
4 | 24 |
202 | 25 |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
26 /* Copy a string |
4 | 27 */ |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
28 gchar *xs_strncpy(gchar *pDest, gchar *pSource, size_t n) |
4 | 29 { |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
30 gchar *s, *d; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
31 size_t i; |
38 | 32 |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
33 /* Check the string pointers */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
34 if (!pSource || !pDest) return pDest; |
4 | 35 |
38 | 36 /* Copy to the destination */ |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
37 i = n; s = pSource; d = pDest; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
38 while (*s && (i > 0)) { *(d++) = *(s++); i--; } |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
39 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
40 /* Fill rest of space with zeros */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
41 while (i > 0) { *(d++) = 0; i--; } |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
42 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
43 /* Ensure that last is always zero */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
44 pDest[n - 1] = 0; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
45 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
46 return pDest; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
47 } |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
48 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
49 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
50 /* Copy a given string over in *ppResult. |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
51 */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
52 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr) |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
53 { |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
54 /* Check the string pointers */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
55 if (!ppResult || !pStr) return -1; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
56 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
57 /* Allocate memory for destination */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
58 if (*ppResult) g_free(*ppResult); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
59 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
60 if (!*ppResult) return -2; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
61 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
62 /* Copy to the destination */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
63 strcpy(*ppResult, pStr); |
4 | 64 |
38 | 65 return 0; |
4 | 66 } |
67 | |
68 | |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
69 /* Concatenates a given string into string pointed by *ppResult. |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
70 */ |
218 | 71 gint th_pstrcat(gchar **ppResult, const gchar *pStr) |
4 | 72 { |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
73 /* Check the string pointers */ |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
74 if (!ppResult || !pStr) return -1; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
75 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
76 if (*ppResult != NULL) |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
77 { |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
78 *ppResult = g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
79 if (*ppResult == NULL) return -1; |
4 | 80 |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
81 strcat(*ppResult, pStr); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
82 } else |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
83 { |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
84 *ppResult = g_malloc(strlen(pStr) + 1); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
85 if (*ppResult == NULL) return -1; |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
86 |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
87 strcpy(*ppResult, pStr); |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
88 } |
4 | 89 |
38 | 90 return 0; |
4 | 91 } |
92 | |
93 | |
206
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
94 /* Locate character in string |
8b896d461fdb
Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents:
202
diff
changeset
|
95 */ |
56
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
96 gchar *xs_strrchr(gchar *pcStr, gchar ch) |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
97 { |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
98 gchar *lastPos = NULL; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
99 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
100 while (*pcStr) |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
101 { |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
102 if (*pcStr == ch) lastPos = pcStr; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
103 pcStr++; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
104 } |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
105 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
106 return lastPos; |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
107 } |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
108 |
6a3ce7260ae1
Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
109 |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
110 inline void xs_findnext(gchar *pcStr, guint *piPos) |
4 | 111 { |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
112 while (pcStr[*piPos] && isspace(pcStr[*piPos])) (*piPos)++; |
4 | 113 } |
114 | |
115 | |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
116 inline void xs_findeol(gchar *pcStr, guint *piPos) |
4 | 117 { |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
118 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) (*piPos)++; |
4 | 119 } |
120 | |
121 | |
109
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
122 inline void xs_findnum(gchar *pcStr, guint *piPos) |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
123 { |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
124 while (pcStr[*piPos] && isdigit(pcStr[*piPos])) (*piPos)++; |
578b71b62eeb
Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
125 } |
214 | 126 |
127 | |
128 #ifndef HAVE_MEMSET | |
129 void *xs_memset(void *p, int c, size_t n) | |
130 { | |
131 gchar *dp; | |
132 | |
133 dp = (gchar *) p; | |
134 while (n--) { *dp = (gchar) c; n--; } | |
135 | |
136 return p; | |
137 } | |
138 #endif |