1 |
twoaday |
2 |
/* w32-glibc.c - Missing W32 stuff from the GLIBC |
2 |
|
|
* |
3 |
|
|
* This program is free software; you can redistribute it and/or modify |
4 |
|
|
* it under the terms of the GNU General Public License as published by |
5 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
6 |
|
|
* (at your option) any later version. |
7 |
|
|
* |
8 |
|
|
* This programis distributed in the hope that it will be useful, |
9 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 |
|
|
* GNU General Public License for more details. |
12 |
|
|
* |
13 |
|
|
* You should have received a copy of the GNU General Public License |
14 |
|
|
* along with this program; if not, write to the Free Software |
15 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
16 |
|
|
*/ |
17 |
|
|
|
18 |
|
|
#include <stdio.h> |
19 |
|
|
#include <string.h> |
20 |
|
|
#include <ctype.h> |
21 |
|
|
#include <malloc.h> |
22 |
|
|
|
23 |
|
|
/********************************************* |
24 |
|
|
********** missing string functions ********* |
25 |
|
|
*********************************************/ |
26 |
|
|
#ifndef HAVE_STPCPY |
27 |
|
|
char * |
28 |
|
|
stpcpy (char *a, const char *b) |
29 |
|
|
{ |
30 |
|
|
while( *b ) |
31 |
|
|
*a++ = *b++; |
32 |
|
|
*a = 0; |
33 |
|
|
|
34 |
|
|
return a; |
35 |
|
|
} |
36 |
|
|
#endif |
37 |
|
|
|
38 |
|
|
#ifndef HAVE_STRSEP |
39 |
|
|
/* code taken from glibc-2.2.1/sysdeps/generic/strsep.c */ |
40 |
|
|
char * |
41 |
|
|
strsep (char **stringp, const char *delim) |
42 |
|
|
{ |
43 |
|
|
char *begin, *end; |
44 |
|
|
begin = *stringp; |
45 |
|
|
|
46 |
|
|
if (begin == NULL) |
47 |
|
|
return NULL; |
48 |
|
|
|
49 |
|
|
/* A frequent case is when the delimiter string contains only one |
50 |
|
|
character. Here we don't need to call the expensive `strpbrk' |
51 |
|
|
function and instead work using `strchr'. */ |
52 |
|
|
if (delim[0] == '\0' || delim[1] == '\0') { |
53 |
|
|
char ch = delim[0]; |
54 |
|
|
if (ch == '\0') |
55 |
|
|
end = NULL; |
56 |
|
|
else { |
57 |
|
|
if (*begin == ch) |
58 |
|
|
end = begin; |
59 |
|
|
else if (*begin == '\0') |
60 |
|
|
end = NULL; |
61 |
|
|
else |
62 |
|
|
end = strchr (begin + 1, ch); |
63 |
|
|
} |
64 |
|
|
} |
65 |
|
|
else /* Find the end of the token. */ |
66 |
|
|
end = strpbrk (begin, delim); |
67 |
|
|
if ( end ){ |
68 |
|
|
/* Terminate the token and set *STRINGP past NUL character. */ |
69 |
|
|
*end++ = '\0'; |
70 |
|
|
*stringp = end; |
71 |
|
|
} |
72 |
|
|
else |
73 |
|
|
/* No more delimiters; this is the last token. */ |
74 |
|
|
*stringp = NULL; |
75 |
|
|
|
76 |
|
|
return begin; |
77 |
|
|
} |
78 |
|
|
|
79 |
|
|
const char * |
80 |
|
|
memistr( const char *buf, size_t buflen, const char *sub ) |
81 |
|
|
{ |
82 |
|
|
const char *t, *s ; |
83 |
|
|
size_t n; |
84 |
|
|
|
85 |
|
|
for( t=buf, n=buflen, s=sub ; n ; t++, n-- ) { |
86 |
|
|
if( toupper(*t) == toupper(*s) ) { |
87 |
|
|
for( buf=t++, buflen = n--, s++; |
88 |
|
|
n && toupper(*t) == toupper(*s); t++, s++, n-- ) |
89 |
|
|
; |
90 |
|
|
if( !*s ) |
91 |
|
|
return buf; |
92 |
|
|
t = buf; n = buflen; s = sub ; |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
return NULL ; |
96 |
|
|
} /* memistr */ |
97 |
|
|
#endif |
98 |
|
|
|
99 |
|
|
|
100 |
|
|
FILE * |
101 |
|
|
my_fopen (const char * fname, const char * mode) |
102 |
|
|
{ |
103 |
|
|
FILE * fp; |
104 |
|
|
char * p; |
105 |
|
|
|
106 |
|
|
if (*fname == '"') { |
107 |
|
|
p = calloc (1, strlen (fname)); |
108 |
|
|
if (!p) |
109 |
|
|
return NULL; |
110 |
|
|
memcpy (p, fname+1, strlen (fname) - 2); |
111 |
|
|
} |
112 |
|
|
else { |
113 |
|
|
p = strdup (fname); |
114 |
|
|
if (!p) |
115 |
|
|
return NULL; |
116 |
|
|
} |
117 |
|
|
fp = fopen (p, mode); |
118 |
|
|
free (p); |
119 |
|
|
return fp; |
120 |
|
|
} |