@@ -92,138 +92,6 @@ private const char *file_or_stream(struct magic_set *, const char *, php_stream
92
92
#define STDIN_FILENO 0
93
93
#endif
94
94
95
- /* XXX this functionality is excluded in php, enable it in apprentice.c:340 */
96
- #if 0
97
- private const char *
98
- get_default_magic (void )
99
- {
100
- static const char hmagic [] = "/.magic/magic.mgc" ;
101
- static char * default_magic ;
102
- char * home , * hmagicpath ;
103
-
104
- #ifndef PHP_WIN32
105
- struct stat st ;
106
-
107
- if (default_magic ) {
108
- free (default_magic );
109
- default_magic = NULL ;
110
- }
111
- if ((home = getenv ("HOME" )) == NULL )
112
- return MAGIC ;
113
-
114
- if (asprintf (& hmagicpath , "%s/.magic.mgc" , home ) < 0 )
115
- return MAGIC ;
116
- if (stat (hmagicpath , & st ) == -1 ) {
117
- free (hmagicpath );
118
- if (asprintf (& hmagicpath , "%s/.magic" , home ) < 0 )
119
- return MAGIC ;
120
- if (stat (hmagicpath , & st ) == -1 )
121
- goto out ;
122
- if (S_ISDIR (st .st_mode )) {
123
- free (hmagicpath );
124
- if (asprintf (& hmagicpath , "%s/%s" , home , hmagic ) < 0 )
125
- return MAGIC ;
126
- if (access (hmagicpath , R_OK ) == -1 )
127
- goto out ;
128
- }
129
- }
130
-
131
- if (asprintf (& default_magic , "%s:%s" , hmagicpath , MAGIC ) < 0 )
132
- goto out ;
133
- free (hmagicpath );
134
- return default_magic ;
135
- out :
136
- default_magic = NULL ;
137
- free (hmagicpath );
138
- return MAGIC ;
139
- #else
140
- char * hmagicp = hmagicpath ;
141
- char * tmppath = NULL ;
142
- LPTSTR dllpath ;
143
-
144
- #define APPENDPATH () \
145
- do { \
146
- if (tmppath && access(tmppath, R_OK) != -1) { \
147
- if (hmagicpath == NULL) \
148
- hmagicpath = tmppath; \
149
- else { \
150
- if (asprintf(&hmagicp, "%s%c%s", hmagicpath, \
151
- PATHSEP, tmppath) >= 0) { \
152
- free(hmagicpath); \
153
- hmagicpath = hmagicp; \
154
- } \
155
- free(tmppath); \
156
- } \
157
- tmppath = NULL; \
158
- } \
159
- } while (/*CONSTCOND*/ 0 )
160
-
161
- if (default_magic ) {
162
- free (default_magic );
163
- default_magic = NULL ;
164
- }
165
-
166
- /* First, try to get user-specific magic file */
167
- if ((home = getenv ("LOCALAPPDATA" )) == NULL ) {
168
- if ((home = getenv ("USERPROFILE" )) != NULL )
169
- if (asprintf (& tmppath ,
170
- "%s/Local Settings/Application Data%s" , home ,
171
- hmagic ) < 0 )
172
- tmppath = NULL ;
173
- } else {
174
- if (asprintf (& tmppath , "%s%s" , home , hmagic ) < 0 )
175
- tmppath = NULL ;
176
- }
177
-
178
- APPENDPATH ();
179
-
180
- /* Second, try to get a magic file from Common Files */
181
- if ((home = getenv ("COMMONPROGRAMFILES" )) != NULL ) {
182
- if (asprintf (& tmppath , "%s%s" , home , hmagic ) >= 0 )
183
- APPENDPATH ();
184
- }
185
-
186
- /* Third, try to get magic file relative to dll location */
187
- dllpath = malloc (sizeof (* dllpath ) * (MAX_PATH + 1 ));
188
- dllpath [MAX_PATH ] = 0 ; /* just in case long path gets truncated and not null terminated */
189
- if (GetModuleFileNameA (NULL , dllpath , MAX_PATH )){
190
- PathRemoveFileSpecA (dllpath );
191
- if (strlen (dllpath ) > 3 &&
192
- stricmp (& dllpath [strlen (dllpath ) - 3 ], "bin" ) == 0 ) {
193
- if (asprintf (& tmppath ,
194
- "%s/../share/misc/magic.mgc" , dllpath ) >= 0 )
195
- APPENDPATH ();
196
- } else {
197
- if (asprintf (& tmppath ,
198
- "%s/share/misc/magic.mgc" , dllpath ) >= 0 )
199
- APPENDPATH ();
200
- else if (asprintf (& tmppath ,
201
- "%s/magic.mgc" , dllpath ) >= 0 )
202
- APPENDPATH ();
203
- }
204
- }
205
-
206
- /* Don't put MAGIC constant - it likely points to a file within MSys
207
- tree */
208
- default_magic = hmagicpath ;
209
- return default_magic ;
210
- #endif
211
- }
212
-
213
- public const char *
214
- magic_getpath (const char * magicfile , int action )
215
- {
216
- if (magicfile != NULL )
217
- return magicfile ;
218
-
219
- magicfile = getenv ("MAGIC" );
220
- if (magicfile != NULL )
221
- return magicfile ;
222
-
223
- return action == FILE_LOAD ? get_default_magic () : MAGIC ;
224
- }
225
- #endif
226
-
227
95
public struct magic_set *
228
96
magic_open (int flags )
229
97
{
0 commit comments