annotate src/xs_support.c @ 324:dd201740a720

Changed copyright text.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Jan 2005 04:11:02 +0000
parents d5aab11eea3d
children b1a858b8cb1a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 Miscellaneous support functions
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 288
diff changeset
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 This program is free software; you can redistribute it and/or modify
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 it under the terms of the GNU General Public License as published by
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 the Free Software Foundation; either version 2 of the License, or
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 (at your option) any later version.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 This program is distributed in the hope that it will be useful,
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 GNU General Public License for more details.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 along with this program; if not, write to the Free Software
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
23 #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
24 #include "xs_support.h"
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
25 #include <ctype.h>
202
fe684a2ccdc7 Reworking code.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
26
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
27
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
28 /* Bigendian file reading functions
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
29 */
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
30 guint16 xs_rd_be16(FILE *f)
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
31 {
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
32 return (((guint16) fgetc(f)) << 8) |
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
33 ((guint16) fgetc(f));
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
34 }
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
35
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
36
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
37 guint32 xs_rd_be32(FILE *f)
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
38 {
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
39 return (((guint32) fgetc(f)) << 24) |
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
40 (((guint32) fgetc(f)) << 16) |
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
41 (((guint32) fgetc(f)) << 8) |
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
42 ((guint32) fgetc(f));
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
43 }
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
44
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
45
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
46 size_t xs_rd_str(FILE *f, gchar *s, size_t l)
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
47 {
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
48 return fread(s, sizeof(gchar), l, f);
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
49 }
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
50
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
51
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
52 /* Copy a string
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 */
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
54 gchar *xs_strncpy(gchar *pDest, gchar *pSource, size_t n)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
56 gchar *s, *d;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
57 size_t i;
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
58
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
59 /* Check the string pointers */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
60 if (!pSource || !pDest) return pDest;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
62 /* Copy to the destination */
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
63 i = n; s = pSource; d = pDest;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
64 while (*s && (i > 0)) { *(d++) = *(s++); i--; }
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
65
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
66 /* Fill rest of space with zeros */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
67 while (i > 0) { *(d++) = 0; i--; }
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
68
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
69 /* Ensure that last is always zero */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
70 pDest[n - 1] = 0;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
71
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
72 return pDest;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
73 }
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
74
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 /* Copy a given string over in *ppResult.
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 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr)
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
79 {
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
80 /* Check the string pointers */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
81 if (!ppResult || !pStr) return -1;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
82
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
83 /* Allocate memory for destination */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
84 if (*ppResult) g_free(*ppResult);
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
85 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
86 if (!*ppResult) return -2;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
87
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
88 /* Copy to the destination */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
89 strcpy(*ppResult, pStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
91 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
95 /* 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
96 */
230
608f31f6c095 Raw cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 226
diff changeset
97 gint xs_pstrcat(gchar **ppResult, const gchar *pStr)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 {
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
99 /* Check the string pointers */
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
100 if (!ppResult || !pStr) return -1;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
101
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
102 if (*ppResult != NULL)
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
103 {
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
104 *ppResult = (gchar *) g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1);
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
105 if (*ppResult == NULL) return -1;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
106 strcat(*ppResult, pStr);
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
107 } else
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
108 {
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
109 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
110 if (*ppResult == NULL) return -1;
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
111 strcpy(*ppResult, pStr);
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
112 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
38
dec37e16136e Minor changes
Matti Hamalainen <ccr@tnsp.org>
parents: 4
diff changeset
114 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
118 /* Concatenate a given string up to given dest size or \n.
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
119 * If size max is reached, change the end to "..."
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
120 */
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
121 void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr)
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
122 {
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
123 size_t i, n;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
124 gchar *s, *d;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
125
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
126 d = pDest; i = 0;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
127 while (*d && (i < iSize)) { i++; d++; }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
128
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
129 s = pStr;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
130 while (*s && (*s != '\n') && (i < iSize))
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
131 {
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
132 *d = *s;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
133 d++; s++; i++;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
134 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
135
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
136 *d = 0;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
137
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
138 if (i >= iSize)
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
139 {
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
140 i--; d--; n = 3;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
141 while ((i > 0) && (n > 0))
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
142 {
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
143 *d = '.';
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
144 d--; i--; n--;
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
145 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
146 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
147 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
148
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
149
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
150 /* Locate character in string
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
151 */
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
152 gchar *xs_strrchr(gchar *pcStr, gchar ch)
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
153 {
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
154 gchar *lastPos = NULL;
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
155
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
156 while (*pcStr)
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
157 {
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
158 if (*pcStr == ch) lastPos = pcStr;
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
159 pcStr++;
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
160 }
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
161
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
162 return lastPos;
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
163 }
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
164
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
165
288
d5aab11eea3d Remove 'inline' defs.
Matti Hamalainen <ccr@tnsp.org>
parents: 239
diff changeset
166 void xs_findnext(gchar *pcStr, guint *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 {
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
168 while (pcStr[*piPos] && isspace(pcStr[*piPos])) (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171
288
d5aab11eea3d Remove 'inline' defs.
Matti Hamalainen <ccr@tnsp.org>
parents: 239
diff changeset
172 void xs_findeol(gchar *pcStr, guint *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 {
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
174 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
288
d5aab11eea3d Remove 'inline' defs.
Matti Hamalainen <ccr@tnsp.org>
parents: 239
diff changeset
178 void xs_findnum(gchar *pcStr, guint *piPos)
109
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
179 {
578b71b62eeb Fileinfo now basically working, STIL COMMENT-fields are not yet parsed or shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
180 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
181 }
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
182
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
183
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
184 #ifndef HAVE_MEMSET
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
185 void *xs_memset(void *p, int c, size_t n)
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
186 {
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
187 gchar *dp;
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
188
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
189 dp = (gchar *) p;
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
190 while (n--) { *dp = (gchar) c; n--; }
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
191
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
192 return p;
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
193 }
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
194 #endif