69
69
# endif
70
70
#endif
71
71
72
- #include "php_filestat .h"
72
+ #include "ext/standard/basic_functions .h"
73
73
74
- #ifndef THREAD_SAFE
75
- static char * CurrentStatFile = NULL ;
76
- # if MSVC5
77
- static unsigned int CurrentStatLength = 0 ;
78
- # else
79
- static int CurrentStatLength = 0 ;
80
- # endif
81
- static struct stat sb ;
82
- #if HAVE_SYMLINK
83
- static struct stat lsb ;
84
- #endif
85
- #endif
74
+ #include "php_filestat.h"
86
75
87
76
#ifndef S_ISDIR
88
77
#define S_ISDIR (mode ) (((mode)&S_IFMT) == S_IFDIR)
@@ -97,16 +86,20 @@ static struct stat lsb;
97
86
98
87
PHP_RINIT_FUNCTION (filestat )
99
88
{
100
- CurrentStatFile = NULL ;
101
- CurrentStatLength = 0 ;
89
+ BLS_FETCH ();
90
+
91
+ BG (CurrentStatFile )= NULL ;
92
+ BG (CurrentStatLength )= 0 ;
102
93
return SUCCESS ;
103
94
}
104
95
105
96
106
97
PHP_RSHUTDOWN_FUNCTION (filestat )
107
98
{
108
- if (CurrentStatFile ) {
109
- efree (CurrentStatFile );
99
+ BLS_FETCH ();
100
+
101
+ if (BG (CurrentStatFile )) {
102
+ efree (BG (CurrentStatFile ));
110
103
}
111
104
return SUCCESS ;
112
105
}
@@ -394,35 +387,40 @@ PHP_FUNCTION(touch)
394
387
395
388
PHP_FUNCTION (clearstatcache )
396
389
{
397
- if (CurrentStatFile ) {
398
- efree (CurrentStatFile );
399
- CurrentStatFile = NULL ;
390
+ BLS_FETCH ();
391
+
392
+ if (BG (CurrentStatFile )) {
393
+ efree (BG (CurrentStatFile ));
394
+ BG (CurrentStatFile ) = NULL ;
400
395
}
401
396
}
402
397
403
398
404
399
static void _php3_stat (const char * filename , int type , pval * return_value )
405
400
{
406
- struct stat * stat_sb = & sb ;
407
-
408
- if (!CurrentStatFile || strcmp (filename ,CurrentStatFile )) {
409
- if (!CurrentStatFile
410
- || strlen (filename ) > CurrentStatLength ) {
411
- if (CurrentStatFile ) efree (CurrentStatFile );
412
- CurrentStatLength = strlen (filename );
413
- CurrentStatFile = estrndup (filename ,CurrentStatLength );
401
+ struct stat * stat_sb ;
402
+ BLS_FETCH ();
403
+
404
+ stat_sb = & BG (sb );
405
+
406
+ if (!BG (CurrentStatFile ) || strcmp (filename ,BG (CurrentStatFile ))) {
407
+ if (!BG (CurrentStatFile )
408
+ || strlen (filename ) > BG (CurrentStatLength )) {
409
+ if (BG (CurrentStatFile )) efree (BG (CurrentStatFile ));
410
+ BG (CurrentStatLength ) = strlen (filename );
411
+ BG (CurrentStatFile ) = estrndup (filename ,BG (CurrentStatLength ));
414
412
} else {
415
- strcpy (CurrentStatFile ,filename );
413
+ strcpy (BG ( CurrentStatFile ) ,filename );
416
414
}
417
415
#if HAVE_SYMLINK
418
- lsb .st_mode = 0 ; /* mark lstat buf invalid */
416
+ BG ( lsb ) .st_mode = 0 ; /* mark lstat buf invalid */
419
417
#endif
420
- if (stat (CurrentStatFile , & sb )== -1 ) {
418
+ if (stat (BG ( CurrentStatFile ), & BG ( sb ) )== -1 ) {
421
419
if (type != 15 || errno != ENOENT ) { /* fileexists() test must print no error */
422
- php_error (E_NOTICE ,"stat failed for %s (errno=%d - %s)" ,CurrentStatFile ,errno ,strerror (errno ));
420
+ php_error (E_NOTICE ,"stat failed for %s (errno=%d - %s)" ,BG ( CurrentStatFile ) ,errno ,strerror (errno ));
423
421
}
424
- efree (CurrentStatFile );
425
- CurrentStatFile = NULL ;
422
+ efree (BG ( CurrentStatFile ) );
423
+ BG ( CurrentStatFile ) = NULL ;
426
424
RETURN_FALSE ;
427
425
}
428
426
}
@@ -434,9 +432,9 @@ static void _php3_stat(const char *filename, int type, pval *return_value)
434
432
435
433
/* do lstat if the buffer is empty */
436
434
437
- if (!lsb .st_mode ) {
438
- if (lstat (CurrentStatFile , & lsb ) == -1 ) {
439
- php_error (E_NOTICE ,"lstat failed for %s (errno=%d - %s)" ,CurrentStatFile ,errno ,strerror (errno ));
435
+ if (!BG ( lsb ) .st_mode ) {
436
+ if (lstat (BG ( CurrentStatFile ), & BG ( lsb ) ) == -1 ) {
437
+ php_error (E_NOTICE ,"lstat failed for %s (errno=%d - %s)" ,BG ( CurrentStatFile ) ,errno ,strerror (errno ));
440
438
RETURN_FALSE ;
441
439
}
442
440
}
@@ -445,57 +443,57 @@ static void _php3_stat(const char *filename, int type, pval *return_value)
445
443
446
444
switch (type ) {
447
445
case 0 : /* fileperms */
448
- RETURN_LONG ((long )sb .st_mode );
446
+ RETURN_LONG ((long )BG ( sb ) .st_mode );
449
447
case 1 : /* fileinode */
450
- RETURN_LONG ((long )sb .st_ino );
448
+ RETURN_LONG ((long )BG ( sb ) .st_ino );
451
449
case 2 : /* filesize */
452
- RETURN_LONG ((long )sb .st_size );
450
+ RETURN_LONG ((long )BG ( sb ) .st_size );
453
451
case 3 : /* fileowner */
454
- RETURN_LONG ((long )sb .st_uid );
452
+ RETURN_LONG ((long )BG ( sb ) .st_uid );
455
453
case 4 : /* filegroup */
456
- RETURN_LONG ((long )sb .st_gid );
454
+ RETURN_LONG ((long )BG ( sb ) .st_gid );
457
455
case 5 : /* fileatime */
458
- RETURN_LONG ((long )sb .st_atime );
456
+ RETURN_LONG ((long )BG ( sb ) .st_atime );
459
457
case 6 : /* filemtime */
460
- RETURN_LONG ((long )sb .st_mtime );
458
+ RETURN_LONG ((long )BG ( sb ) .st_mtime );
461
459
case 7 : /* filectime */
462
- RETURN_LONG ((long )sb .st_ctime );
460
+ RETURN_LONG ((long )BG ( sb ) .st_ctime );
463
461
case 8 : /* filetype */
464
462
#if HAVE_SYMLINK
465
- if (S_ISLNK (lsb .st_mode )) {
463
+ if (S_ISLNK (BG ( lsb ) .st_mode )) {
466
464
RETURN_STRING ("link" ,1 );
467
465
}
468
466
#endif
469
- switch (sb .st_mode & S_IFMT ) {
467
+ switch (BG ( sb ) .st_mode & S_IFMT ) {
470
468
case S_IFIFO : RETURN_STRING ("fifo" ,1 );
471
469
case S_IFCHR : RETURN_STRING ("char" ,1 );
472
470
case S_IFDIR : RETURN_STRING ("dir" ,1 );
473
471
case S_IFBLK : RETURN_STRING ("block" ,1 );
474
472
case S_IFREG : RETURN_STRING ("file" ,1 );
475
473
}
476
- php_error (E_WARNING ,"Unknown file type (%d)" ,sb .st_mode & S_IFMT );
474
+ php_error (E_WARNING ,"Unknown file type (%d)" ,BG ( sb ) .st_mode & S_IFMT );
477
475
RETURN_STRING ("unknown" ,1 );
478
476
case 9 : /*is writable*/
479
- RETURN_LONG ((sb .st_mode & S_IWRITE )!= 0 );
477
+ RETURN_LONG ((BG ( sb ) .st_mode & S_IWRITE )!= 0 );
480
478
case 10 : /*is readable*/
481
- RETURN_LONG ((sb .st_mode & S_IREAD )!= 0 );
479
+ RETURN_LONG ((BG ( sb ) .st_mode & S_IREAD )!= 0 );
482
480
case 11 : /*is executable*/
483
- RETURN_LONG ((sb .st_mode & S_IEXEC )!= 0 && !S_ISDIR (sb .st_mode ));
481
+ RETURN_LONG ((BG ( sb ) .st_mode & S_IEXEC )!= 0 && !S_ISDIR (BG ( sb ) .st_mode ));
484
482
case 12 : /*is file*/
485
- RETURN_LONG (S_ISREG (sb .st_mode ));
483
+ RETURN_LONG (S_ISREG (BG ( sb ) .st_mode ));
486
484
case 13 : /*is dir*/
487
- RETURN_LONG (S_ISDIR (sb .st_mode ));
485
+ RETURN_LONG (S_ISDIR (BG ( sb ) .st_mode ));
488
486
case 14 : /*is link*/
489
487
#if HAVE_SYMLINK
490
- RETURN_LONG (S_ISLNK (lsb .st_mode ));
488
+ RETURN_LONG (S_ISLNK (BG ( lsb ) .st_mode ));
491
489
#else
492
490
RETURN_FALSE ;
493
491
#endif
494
492
case 15 : /*file exists*/
495
493
RETURN_TRUE ; /* the false case was done earlier */
496
494
case 16 : /* lstat */
497
495
#if HAVE_SYMLINK
498
- stat_sb = & lsb ;
496
+ stat_sb = & BG ( lsb ) ;
499
497
#endif
500
498
/* FALLTHROUGH */
501
499
case 17 : /* stat */
0 commit comments