comparison src/xs_support.c @ 398:933b9ea5923e

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 31 May 2006 13:00:05 +0000
parents b1a858b8cb1a
children 7f694e5a1493
comparison
equal deleted inserted replaced
397:c4e5604a8257 398:933b9ea5923e
25 #include <ctype.h> 25 #include <ctype.h>
26 26
27 27
28 /* Bigendian file reading functions 28 /* Bigendian file reading functions
29 */ 29 */
30 guint16 xs_rd_be16(FILE * f) 30 guint16 xs_rd_be16(FILE *f)
31 { 31 {
32 return (((guint16) fgetc(f)) << 8) | ((guint16) fgetc(f)); 32 return (((guint16) fgetc(f)) << 8) | ((guint16) fgetc(f));
33 } 33 }
34 34
35 35
36 guint32 xs_rd_be32(FILE * f) 36 guint32 xs_rd_be32(FILE *f)
37 { 37 {
38 return (((guint32) fgetc(f)) << 24) | 38 return (((guint32) fgetc(f)) << 24) |
39 (((guint32) fgetc(f)) << 16) | (((guint32) fgetc(f)) << 8) | ((guint32) fgetc(f)); 39 (((guint32) fgetc(f)) << 16) | (((guint32) fgetc(f)) << 8) | ((guint32) fgetc(f));
40 } 40 }
41 41
42 42
43 size_t xs_rd_str(FILE * f, gchar * s, size_t l) 43 size_t xs_rd_str(FILE *f, gchar *s, size_t l)
44 { 44 {
45 return fread(s, sizeof(gchar), l, f); 45 return fread(s, sizeof(gchar), l, f);
46 } 46 }
47 47
48 48
49 /* Copy a string 49 /* Copy a string
50 */ 50 */
51 gchar *xs_strncpy(gchar * pDest, gchar * pSource, size_t n) 51 gchar *xs_strncpy(gchar *pDest, gchar *pSource, size_t n)
52 { 52 {
53 gchar *s, *d; 53 gchar *s, *d;
54 size_t i; 54 size_t i;
55 55
56 /* Check the string pointers */ 56 /* Check the string pointers */
79 } 79 }
80 80
81 81
82 /* Copy a given string over in *ppResult. 82 /* Copy a given string over in *ppResult.
83 */ 83 */
84 gint xs_pstrcpy(gchar ** ppResult, const gchar * pStr) 84 gint xs_pstrcpy(gchar **ppResult, const gchar *pStr)
85 { 85 {
86 /* Check the string pointers */ 86 /* Check the string pointers */
87 if (!ppResult || !pStr) 87 if (!ppResult || !pStr)
88 return -1; 88 return -1;
89 89
101 } 101 }
102 102
103 103
104 /* Concatenates a given string into string pointed by *ppResult. 104 /* Concatenates a given string into string pointed by *ppResult.
105 */ 105 */
106 gint xs_pstrcat(gchar ** ppResult, const gchar * pStr) 106 gint xs_pstrcat(gchar **ppResult, const gchar *pStr)
107 { 107 {
108 /* Check the string pointers */ 108 /* Check the string pointers */
109 if (!ppResult || !pStr) 109 if (!ppResult || !pStr)
110 return -1; 110 return -1;
111 111
126 126
127 127
128 /* Concatenate a given string up to given dest size or \n. 128 /* Concatenate a given string up to given dest size or \n.
129 * If size max is reached, change the end to "..." 129 * If size max is reached, change the end to "..."
130 */ 130 */
131 void xs_pnstrcat(gchar * pDest, size_t iSize, gchar * pStr) 131 void xs_pnstrcat(gchar *pDest, size_t iSize, gchar *pStr)
132 { 132 {
133 size_t i, n; 133 size_t i, n;
134 gchar *s, *d; 134 gchar *s, *d;
135 135
136 d = pDest; 136 d = pDest;
164 } 164 }
165 165
166 166
167 /* Locate character in string 167 /* Locate character in string
168 */ 168 */
169 gchar *xs_strrchr(gchar * pcStr, gchar ch) 169 gchar *xs_strrchr(gchar *pcStr, gchar ch)
170 { 170 {
171 gchar *lastPos = NULL; 171 gchar *lastPos = NULL;
172 172
173 while (*pcStr) { 173 while (*pcStr) {
174 if (*pcStr == ch) 174 if (*pcStr == ch)
178 178
179 return lastPos; 179 return lastPos;
180 } 180 }
181 181
182 182
183 void xs_findnext(gchar * pcStr, guint * piPos) 183 void xs_findnext(gchar *pcStr, guint *piPos)
184 { 184 {
185 while (pcStr[*piPos] && isspace(pcStr[*piPos])) 185 while (pcStr[*piPos] && isspace(pcStr[*piPos]))
186 (*piPos)++; 186 (*piPos)++;
187 } 187 }
188 188
189 189
190 void xs_findeol(gchar * pcStr, guint * piPos) 190 void xs_findeol(gchar *pcStr, guint *piPos)
191 { 191 {
192 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r')) 192 while (pcStr[*piPos] && (pcStr[*piPos] != '\n') && (pcStr[*piPos] != '\r'))
193 (*piPos)++; 193 (*piPos)++;
194 } 194 }
195 195
196 196
197 void xs_findnum(gchar * pcStr, guint * piPos) 197 void xs_findnum(gchar *pcStr, guint *piPos)
198 { 198 {
199 while (pcStr[*piPos] && isdigit(pcStr[*piPos])) 199 while (pcStr[*piPos] && isdigit(pcStr[*piPos]))
200 (*piPos)++; 200 (*piPos)++;
201 } 201 }
202 202