annotate src/xs_support.c @ 506:d87ac4d5dc52

guint -> size_t
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 28 Jan 2007 13:40:05 +0000
parents 00a32ab5887d
children c192468eb8ce
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>
422
d2e6682d3ef8 Copyright year update
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
7 (C) Copyright 1999-2007 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
412
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
19 You should have received a copy of the GNU General Public License along
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
20 with this program; if not, write to the Free Software Foundation, Inc.,
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
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"
224
df4cb5115322 Removed duplicate function, more portability cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 218
diff changeset
24 #include <ctype.h>
202
fe684a2ccdc7 Reworking code.
Matti Hamalainen <ccr@tnsp.org>
parents: 109
diff changeset
25
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
26
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
27 /* File handling
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
28 */
466
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
29 t_xs_file *xs_fopen(const gchar *path, const gchar *mode)
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
30 {
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
31 return fopen(path, mode);
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
32 }
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
33
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
34
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
35 gint xs_fclose(t_xs_file *f)
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
36 {
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
37 return fclose(f);
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
38 }
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
39
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
40
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
41 gint xs_fgetc(t_xs_file *f)
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
42 {
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
43 return fgetc(f);
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
44 }
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
45
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
46
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
47 guint16 xs_fread_be16(t_xs_file *f)
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
48 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
49 return (((guint16) fgetc(f)) << 8) | ((guint16) fgetc(f));
226
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
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
52
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
53 guint32 xs_fread_be32(t_xs_file *f)
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
54 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
55 return (((guint32) fgetc(f)) << 24) |
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
56 (((guint32) fgetc(f)) << 16) |
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
57 (((guint32) fgetc(f)) << 8) |
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
58 ((guint32) fgetc(f));
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
59 }
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
60
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
61
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
62 size_t xs_fread(void *p, size_t s, size_t n, t_xs_file *f)
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
63 {
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
64 return fread(p, s, n, f);
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
65 }
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
66
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
67
466
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
68 gint xs_feof(t_xs_file *f)
452
aec9f4beb401 New file reading functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 428
diff changeset
69 {
466
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
70 return feof(f);
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
71 }
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
72
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
73
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
74 gint xs_ferror(t_xs_file *f)
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
75 {
00a32ab5887d Moved some things from xmms-sid.h to xs_support.h; File handling functions
Matti Hamalainen <ccr@tnsp.org>
parents: 452
diff changeset
76 return ferror(f);
226
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
77 }
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
78
858c09f59011 Moved some functions from xs_length.c here.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
79
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
80 /* Copy a string
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
82 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
83 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
84 gchar *s, *d;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
85 size_t i;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
86
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
87 /* Check the string pointers */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
88 if (!pSource || !pDest)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
89 return pDest;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
91 /* Copy to the destination */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
92 i = n;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
93 s = pSource;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
94 d = pDest;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
95 while (*s && (i > 0)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
96 *(d++) = *(s++);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
97 i--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
98 }
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
99
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
100 /* Fill rest of space with zeros */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
101 while (i > 0) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
102 *(d++) = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
103 i--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
104 }
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
105
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
106 /* Ensure that last is always zero */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
107 pDest[n - 1] = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
108
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
109 return pDest;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
110 }
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
111
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
112
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
113 /* Copy a given string over in *ppResult.
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
114 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
115 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr)
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
116 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
117 /* Check the string pointers */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
118 if (!ppResult || !pStr)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
119 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
120
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
121 /* Allocate memory for destination */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
122 if (*ppResult)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
123 g_free(*ppResult);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
124 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
125 if (!*ppResult)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
126 return -2;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
127
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
128 /* Copy to the destination */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
129 strcpy(*ppResult, pStr);
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
131 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
135 /* 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
136 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
137 gint xs_pstrcat(gchar **ppResult, const gchar *pStr)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
139 /* Check the string pointers */
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
140 if (!ppResult || !pStr)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
141 return -1;
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
142
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
143 if (*ppResult != NULL) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
144 *ppResult = (gchar *) g_realloc(*ppResult, strlen(*ppResult) + strlen(pStr) + 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
145 if (*ppResult == NULL)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
146 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
147 strcat(*ppResult, pStr);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
148 } else {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
149 *ppResult = (gchar *) g_malloc(strlen(pStr) + 1);
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
150 if (*ppResult == NULL)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
151 return -1;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
152 strcpy(*ppResult, pStr);
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
153 }
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
155 return 0;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
159 /* 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
160 * 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
161 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
162 void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr)
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
163 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
164 size_t i, n;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
165 gchar *s, *d;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
166
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
167 d = pDest;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
168 i = 0;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
169 while (*d && (i < iSize)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
170 i++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
171 d++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
172 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
173
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
174 s = pStr;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
175 while (*s && (*s != '\n') && (i < iSize)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
176 *d = *s;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
177 d++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
178 s++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
179 i++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
180 }
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
181
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
182 *d = 0;
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
183
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
184 if (i >= iSize) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
185 i--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
186 d--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
187 n = 3;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
188 while ((i > 0) && (n > 0)) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
189 *d = '.';
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
190 d--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
191 i--;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
192 n--;
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
193 }
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
194 }
239
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
195 }
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
196
7833df935239 Added xs_pnstrcat() to ease forming of limited size strings.
Matti Hamalainen <ccr@tnsp.org>
parents: 230
diff changeset
197
206
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
198 /* Locate character in string
8b896d461fdb Trivial fixes and added strncpy replacement.
Matti Hamalainen <ccr@tnsp.org>
parents: 202
diff changeset
199 */
398
933b9ea5923e Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
200 gchar *xs_strrchr(gchar *pcStr, gchar ch)
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
201 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
202 gchar *lastPos = NULL;
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
203
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
204 while (*pcStr) {
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
205 if (*pcStr == ch)
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
206 lastPos = pcStr;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
207 pcStr++;
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
208 }
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
209
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
210 return lastPos;
56
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
211 }
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
212
6a3ce7260ae1 Changed some standard functions to glib ones
Matti Hamalainen <ccr@tnsp.org>
parents: 49
diff changeset
213
506
d87ac4d5dc52 guint -> size_t
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
214 void xs_findnext(gchar *pcStr, size_t *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
216 while (pcStr[*piPos] && isspace(pcStr[*piPos]))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
217 (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220
506
d87ac4d5dc52 guint -> size_t
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
221 void xs_findeol(gchar *pcStr, size_t *piPos)
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
223 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r'))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
224 (*piPos)++;
4
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 }
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226
4bb09e405eab Added new files for 0.8
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227
506
d87ac4d5dc52 guint -> size_t
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
228 void xs_findnum(gchar *pcStr, size_t *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
229 {
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
230 while (pcStr[*piPos] && isdigit(pcStr[*piPos]))
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
231 (*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
232 }
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
233
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
234
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
235 #ifndef HAVE_MEMSET
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
236 void *xs_memset(void *p, int c, size_t n)
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
237 {
428
33c3bb80d2a5 Urgh, xs_memset() was buggy :P
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
238 guint8 *dp;
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
239
428
33c3bb80d2a5 Urgh, xs_memset() was buggy :P
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
240 dp = (guint8 *) p;
33c3bb80d2a5 Urgh, xs_memset() was buggy :P
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
241 while (n--)
33c3bb80d2a5 Urgh, xs_memset() was buggy :P
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
242 *dp = c;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
243
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 324
diff changeset
244 return p;
214
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
245 }
575686094eb1 Portability fixes
Matti Hamalainen <ccr@tnsp.org>
parents: 206
diff changeset
246 #endif