7
7
#include <stdlib.h>
8
8
#include <ctype.h>
9
9
10
-
11
10
#include "php_virtual_cwd.h"
12
11
12
+ #define VIRTUAL_CWD_DEBUG 0
13
+
13
14
#ifdef ZTS
14
15
#include "TSRM.h"
15
16
#endif
@@ -148,6 +149,9 @@ CWD_API void virtual_cwd_startup()
148
149
149
150
CWD_API void virtual_cwd_activate (char * filename )
150
151
{
152
+ #if VIRTUAL_CWD_DEBUG
153
+ fprintf (stderr , "Changing dir to %s\n" , filename );
154
+ #endif
151
155
if (filename ) {
152
156
virtual_chdir_file (filename );
153
157
}
@@ -238,7 +242,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
238
242
239
243
old_state = (cwd_state * ) malloc (sizeof (cwd_state ));
240
244
CWD_STATE_COPY (old_state , state );
241
-
245
+ #if VIRTUAL_CWD_DEBUG
246
+ fprintf (stderr ,"cwd = %s path = %s\n" , state -> cwd , path );
247
+ #endif
242
248
if (IS_ABSOLUTE_PATH (path_copy , path_length )) {
243
249
copy_amount = COPY_WHEN_ABSOLUTE ;
244
250
is_absolute = 1 ;
@@ -310,7 +316,9 @@ CWD_API int virtual_file_ex(cwd_state *state, const char *path, verify_path_func
310
316
free (old_state );
311
317
312
318
efree (free_path );
313
-
319
+ #if VIRTUAL_CWD_DEBUG
320
+ fprintf (stderr , "virtual_file_ex() = %s\n" ,state -> cwd );
321
+ #endif
314
322
return (ret );
315
323
}
316
324
@@ -324,6 +332,8 @@ CWD_API int virtual_chdir(char *path)
324
332
CWD_API int virtual_chdir_file (char * path )
325
333
{
326
334
int length = strlen (path );
335
+ char * temp ;
336
+ int retval ;
327
337
328
338
if (length == 0 ) {
329
339
return 1 ; /* Can't cd to empty string */
@@ -334,8 +344,16 @@ CWD_API int virtual_chdir_file(char *path)
334
344
if (length == -1 ) {
335
345
return virtual_chdir (path );
336
346
}
337
- path [length ] = DEFAULT_SLASH ;
338
- return virtual_chdir (path );
347
+
348
+ temp = (char * ) malloc (length + 1 );
349
+ memcpy (temp , path , length );
350
+ temp [length ] = 0 ;
351
+ #if VIRTUAL_CWD_DEBUG
352
+ fprintf (stderr , "Changing directory to %s\n" , temp );
353
+ #endif
354
+ retval = virtual_chdir (temp );
355
+ free (temp );
356
+ return retval ;
339
357
}
340
358
341
359
@@ -382,6 +400,21 @@ CWD_API int virtual_stat(const char *path, struct stat *buf)
382
400
return retval ;
383
401
}
384
402
403
+ CWD_API int virtual_lstat (const char * path , struct stat * buf )
404
+ {
405
+ cwd_state new_state ;
406
+ int retval ;
407
+ CWDLS_FETCH ();
408
+
409
+ CWD_STATE_COPY (& new_state , & CWDG (cwd ));
410
+
411
+ virtual_file_ex (& new_state , path , NULL );
412
+
413
+ retval = lstat (new_state .cwd , buf );
414
+ CWD_STATE_FREE (& new_state );
415
+ return retval ;
416
+ }
417
+
385
418
#if 0
386
419
387
420
main (void )
0 commit comments