ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/fptools.c
(Generate patch)

Comparing Convert-UUlib/uulib/fptools.c (file contents):
Revision 1.3 by root, Sun Feb 10 22:47:18 2002 UTC vs.
Revision 1.3.2.2 by root, Sun Mar 31 19:52:07 2002 UTC

20 * This file provides replacements for some handy functions that aren't 20 * This file provides replacements for some handy functions that aren't
21 * available on all systems, like most of the <string.h> functions. They 21 * available on all systems, like most of the <string.h> functions. They
22 * should behave exactly as their counterparts. There are also extensions 22 * should behave exactly as their counterparts. There are also extensions
23 * that aren't portable at all (like strirstr etc.). 23 * that aren't portable at all (like strirstr etc.).
24 * The proper behaviour in a configure script is as follows: 24 * The proper behaviour in a configure script is as follows:
25 * AC_CHECK_FUNC(strrchr,AC_DEFINE(strrchr,FP_strrchr)) 25 * AC_CHECK_FUNC(strrchr,AC_DEFINE(strrchr,_FP_strrchr))
26 * This way, the (probably less efficient) replacements will only be used 26 * This way, the (probably less efficient) replacements will only be used
27 * where it is not provided by the default libraries. Be aware that this 27 * where it is not provided by the default libraries. Be aware that this
28 * does not work with replacements that just shadow wrong behaviour (like 28 * does not work with replacements that just shadow wrong behaviour (like
29 * FP_free) or provide extended functionality (FP_gets). 29 * _FP_free) or provide extended functionality (_FP_gets).
30 * The above is not used in the uuenview/uudeview configuration script, 30 * The above is not used in the uuenview/uudeview configuration script,
31 * since both only use the replacement functions in non-performance-cri- 31 * since both only use the replacement functions in non-performance-cri-
32 * tical sections (except for FP_tempnam and FP_strerror, where some 32 * tical sections (except for _FP_tempnam and _FP_strerror, where some
33 * functionality of the original would be lost). 33 * functionality of the original would be lost).
34 */ 34 */
35 35
36#include <stdio.h> 36#include <stdio.h>
37#include <ctype.h> 37#include <ctype.h>
62 return TRUE; 62 return TRUE;
63} 63}
64#endif 64#endif
65#endif 65#endif
66 66
67char * fptools_id = "$Id: fptools.c,v 1.3 2002/02/10 22:47:18 root Exp $"; 67char * fptools_id = "$Id: fptools.c,v 1.3.2.2 2002/03/31 19:52:07 root Exp $";
68 68
69/* 69/*
70 * some versions of free can't handle a NULL pointer properly 70 * some versions of free can't handle a NULL pointer properly
71 * (ANSI says, free ignores a NULL pointer, but some machines 71 * (ANSI says, free ignores a NULL pointer, but some machines
72 * prefer to SIGSEGV on it) 72 * prefer to SIGSEGV on it)
73 */ 73 */
74 74
75void TOOLEXPORT 75void TOOLEXPORT
76FP_free (void *ptr) 76_FP_free (void *ptr)
77{ 77{
78 if (ptr) free (ptr); 78 if (ptr) free (ptr);
79} 79}
80 80
81/* 81/*
82 * This is non-standard, so I'm defining my own 82 * This is non-standard, so I'm defining my own
83 */ 83 */
84 84
85char * TOOLEXPORT 85char * TOOLEXPORT
86FP_strdup (char *string) 86_FP_strdup (char *string)
87{ 87{
88 char *result; 88 char *result;
89 89
90 if (string == NULL) 90 if (string == NULL)
91 return NULL; 91 return NULL;
102 * the original in that the dest string is always terminated with a 102 * the original in that the dest string is always terminated with a
103 * NULL character. 103 * NULL character.
104 */ 104 */
105 105
106char * TOOLEXPORT 106char * TOOLEXPORT
107FP_strncpy (char *dest, char *src, int length) 107_FP_strncpy (char *dest, char *src, int length)
108{ 108{
109 char *odest=dest; 109 char *odest=dest;
110 if (src == NULL || dest == NULL || length-- <= 0) 110 if (src == NULL || dest == NULL || length-- <= 0)
111 return dest; 111 return dest;
112 112
120/* 120/*
121 * duplicate a memory area 121 * duplicate a memory area
122 */ 122 */
123 123
124void * TOOLEXPORT 124void * TOOLEXPORT
125FP_memdup (void *ptr, int len) 125_FP_memdup (void *ptr, int len)
126{ 126{
127 void *result; 127 void *result;
128 128
129 if (ptr == NULL) 129 if (ptr == NULL)
130 return NULL; 130 return NULL;
139/* 139/*
140 * case-insensitive compare 140 * case-insensitive compare
141 */ 141 */
142 142
143int TOOLEXPORT 143int TOOLEXPORT
144FP_stricmp (char *str1, char *str2) 144_FP_stricmp (char *str1, char *str2)
145{ 145{
146 if (str1==NULL || str2==NULL) 146 if (str1==NULL || str2==NULL)
147 return -1; 147 return -1;
148 148
149 while (*str1) { 149 while (*str1) {
154 } 154 }
155 return (tolower (*str1) - tolower (*str2)); 155 return (tolower (*str1) - tolower (*str2));
156} 156}
157 157
158int TOOLEXPORT 158int TOOLEXPORT
159FP_strnicmp (char *str1, char *str2, int count) 159_FP_strnicmp (char *str1, char *str2, int count)
160{ 160{
161 if (str1==NULL || str2==NULL) 161 if (str1==NULL || str2==NULL)
162 return -1; 162 return -1;
163 163
164 while (*str1 && count) { 164 while (*str1 && count) {
174/* 174/*
175 * autoconf says this function might be a compatibility problem 175 * autoconf says this function might be a compatibility problem
176 */ 176 */
177 177
178char * TOOLEXPORT 178char * TOOLEXPORT
179FP_strstr (char *str1, char *str2) 179_FP_strstr (char *str1, char *str2)
180{ 180{
181 char *ptr1, *ptr2; 181 char *ptr1, *ptr2;
182 182
183 if (str1==NULL) 183 if (str1==NULL)
184 return NULL; 184 return NULL;
197 } 197 }
198 return NULL; 198 return NULL;
199} 199}
200 200
201char * TOOLEXPORT 201char * TOOLEXPORT
202FP_strpbrk (char *str, char *accept) 202_FP_strpbrk (char *str, char *accept)
203{ 203{
204 char *ptr; 204 char *ptr;
205 205
206 if (str == NULL) 206 if (str == NULL)
207 return NULL; 207 return NULL;
219/* 219/*
220 * autoconf also complains about this one 220 * autoconf also complains about this one
221 */ 221 */
222 222
223char * TOOLEXPORT 223char * TOOLEXPORT
224FP_strtok (char *str1, char *str2) 224_FP_strtok (char *str1, char *str2)
225{ 225{
226 static char *optr; 226 static char *optr;
227 char *ptr; 227 char *ptr;
228 228
229 if (str2 == NULL) 229 if (str2 == NULL)
256/* 256/*
257 * case insensitive strstr. 257 * case insensitive strstr.
258 */ 258 */
259 259
260char * TOOLEXPORT 260char * TOOLEXPORT
261FP_stristr (char *str1, char *str2) 261_FP_stristr (char *str1, char *str2)
262{ 262{
263 char *ptr1, *ptr2; 263 char *ptr1, *ptr2;
264 264
265 if (str1==NULL) 265 if (str1==NULL)
266 return NULL; 266 return NULL;
283/* 283/*
284 * Nice fake of the real (non-standard) one 284 * Nice fake of the real (non-standard) one
285 */ 285 */
286 286
287char * TOOLEXPORT 287char * TOOLEXPORT
288FP_strrstr (char *ptr, char *str) 288_FP_strrstr (char *ptr, char *str)
289{ 289{
290 char *found=NULL, *new, *iter=ptr; 290 char *found=NULL, *new, *iter=ptr;
291 291
292 if (ptr==NULL || str==NULL) 292 if (ptr==NULL || str==NULL)
293 return NULL; 293 return NULL;
294 294
295 if (*str == '\0') 295 if (*str == '\0')
296 return ptr; 296 return ptr;
297 297
298 while ((new = FP_strstr (iter, str)) != NULL) { 298 while ((new = _FP_strstr (iter, str)) != NULL) {
299 found = new; 299 found = new;
300 iter = new + 1; 300 iter = new + 1;
301 } 301 }
302 return found; 302 return found;
303} 303}
304 304
305char * TOOLEXPORT 305char * TOOLEXPORT
306FP_strirstr (char *ptr, char *str) 306_FP_strirstr (char *ptr, char *str)
307{ 307{
308 char *found=NULL, *iter=ptr, *new; 308 char *found=NULL, *iter=ptr, *new;
309 309
310 if (ptr==NULL || str==NULL) 310 if (ptr==NULL || str==NULL)
311 return NULL; 311 return NULL;
312 if (*str == '\0') 312 if (*str == '\0')
313 return ptr; 313 return ptr;
314 314
315 while ((new = FP_stristr (iter, str)) != NULL) { 315 while ((new = _FP_stristr (iter, str)) != NULL) {
316 found = new; 316 found = new;
317 iter = new + 1; 317 iter = new + 1;
318 } 318 }
319 return found; 319 return found;
320} 320}
322/* 322/*
323 * convert whole string to case 323 * convert whole string to case
324 */ 324 */
325 325
326char * TOOLEXPORT 326char * TOOLEXPORT
327FP_stoupper (char *input) 327_FP_stoupper (char *input)
328{ 328{
329 char *iter = input; 329 char *iter = input;
330 330
331 if (input == NULL) 331 if (input == NULL)
332 return NULL; 332 return NULL;
337 } 337 }
338 return input; 338 return input;
339} 339}
340 340
341char * TOOLEXPORT 341char * TOOLEXPORT
342FP_stolower (char *input) 342_FP_stolower (char *input)
343{ 343{
344 char *iter = input; 344 char *iter = input;
345 345
346 if (input == NULL) 346 if (input == NULL)
347 return NULL; 347 return NULL;
356/* 356/*
357 * string matching with wildcards 357 * string matching with wildcards
358 */ 358 */
359 359
360int TOOLEXPORT 360int TOOLEXPORT
361FP_strmatch (char *string, char *pattern) 361_FP_strmatch (char *string, char *pattern)
362{ 362{
363 char *p1 = string, *p2 = pattern; 363 char *p1 = string, *p2 = pattern;
364 364
365 if (pattern==NULL || string==NULL) 365 if (pattern==NULL || string==NULL)
366 return 0; 366 return 0;
386 386
387 return 1; 387 return 1;
388} 388}
389 389
390char * TOOLEXPORT 390char * TOOLEXPORT
391FP_strrchr (char *string, int tc) 391_FP_strrchr (char *string, int tc)
392{ 392{
393 char *ptr; 393 char *ptr;
394 394
395 if (string == NULL) 395 if (string == NULL)
396 return NULL; 396 return NULL;
410 * strip directory information from a filename. Works only on DOS and 410 * strip directory information from a filename. Works only on DOS and
411 * Unix systems so far ... 411 * Unix systems so far ...
412 */ 412 */
413 413
414char * TOOLEXPORT 414char * TOOLEXPORT
415FP_cutdir (char *filename) 415_FP_cutdir (char *filename)
416{ 416{
417 char *ptr; 417 char *ptr;
418 418
419 if (filename == NULL) 419 if (filename == NULL)
420 return NULL; 420 return NULL;
421 421
422 if ((ptr = FP_strrchr (filename, '/')) != NULL) 422 if ((ptr = _FP_strrchr (filename, '/')) != NULL)
423 ptr++; 423 ptr++;
424 else if ((ptr = FP_strrchr (filename, '\\')) != NULL) 424 else if ((ptr = _FP_strrchr (filename, '\\')) != NULL)
425 ptr++; 425 ptr++;
426 else 426 else
427 ptr = filename; 427 ptr = filename;
428 428
429 return ptr; 429 return ptr;
434 * properly: LF (Unix), CRLF (DOS) and CR (Mac). In all cases, the 434 * properly: LF (Unix), CRLF (DOS) and CR (Mac). In all cases, the
435 * terminator is replaced by a single LF 435 * terminator is replaced by a single LF
436 */ 436 */
437 437
438char * TOOLEXPORT 438char * TOOLEXPORT
439FP_fgets (char *buf, int n, FILE *stream) 439_FP_fgets (char *buf, int n, FILE *stream)
440{ 440{
441 char *obp = buf; 441 char *obp = buf;
442 int c; 442 int c;
443 443
444 if (feof (stream)) 444 if (feof (stream))
489/* 489/*
490 * A replacement strerror function that just returns the error code 490 * A replacement strerror function that just returns the error code
491 */ 491 */
492 492
493char * TOOLEXPORT 493char * TOOLEXPORT
494FP_strerror (int errcode) 494_FP_strerror (int errcode)
495{ 495{
496 static char number[8]; 496 static char number[8];
497 497
498 sprintf (number, "%03d", errcode); 498 sprintf (number, "%03d", errcode);
499 499
500 return number; 500 return number;
501} 501}
502#ifndef HAVE_MKSTEMP 502
503/* 503/*
504 * tempnam is not ANSI, but tmpnam is. Ignore the prefix here. 504 * tempnam is not ANSI, but tmpnam is. Ignore the prefix here.
505 */ 505 */
506 506
507char * TOOLEXPORT 507char * TOOLEXPORT
508FP_tempnam (char *dir, char *pfx) 508_FP_tempnam (char *dir, char *pfx)
509{ 509{
510 return FP_strdup (tmpnam (NULL)); 510 return _FP_strdup (tmpnam (NULL));
511} 511}
512#endif /* HAVE_MKSTEMP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines