#!perl -w use strict; my $exe = '../perl.exe'; stat($exe); printf "BAD $exe text=%d, executable=%d\n", -T _, -x _; stat($exe); printf "OK $exe executable=%d, text=%d\n", -x _, -T _; stat($exe); printf "OK $exe text=%d, executable=%d\n", -T _, -x $exe; __END__ BAD ../perl.exe text=0, executable=0 OK ../perl.exe executable=1, text=0 OK ../perl.exe text=0, executable=1 #### Perl_pp_stat() in pp_sys.c implements Perl stat() calls PerlLIONameStat() calls win32_stat() calls stat(path, sbuf) // Win32 library call sbuf.st_mode == 0100777 octal, for perl.exe, GOOD Perl_pp_fttext() in pp_sys.c implements Perl -T calls PerlLIOFileStat() calls win32_fstat() calls my_fstat() calls fstat(fd, sbuf) // Win32 library call sbuf.st_mode == 0100666 octal, for perl.exe, BAD #### // _stattest.cpp : compare MS implementation of functions stat() and fstat() // rudif@bluemail.ch 1 Jul 2001 #include #include #include #include #include #include void main( void ) { const char *filename = "c:\\perl\\bin\\perl.exe"; printf( "File name : %s\n", filename ); { static struct stat buf; // initializes to 0 if ( stat( filename, &buf ) != 0 ) perror( "Problem with stat()" ); else { printf( "\nFrom MSDN page on _stat():\n" " Get status information on a file.\n" " st_mode\n" " Bit mask for file-mode information.\n" " The _S_IFDIR bit is set if path specifies a directory;\n" " the _S_IFREG bit is set if path specifies an ordinary file or a device.\n" " User read/write bits are set according to the file’s permission mode;\n" " user execute bits are set according to the filename extension.\n" ); printf( "Mode (oct) : 0%06o\n", (unsigned short)buf.st_mode ); printf( "Mode (hex) : 0x%04x\n", (unsigned short)buf.st_mode ); } } { int fh; static struct stat buf; // initializes to 0 if ( (fh = open(filename, _O_RDONLY)) == -1 ) perror( "Problem with open()" ); else if ( fstat( fh, &buf ) != 0 ) perror( "Problem with fstat()" ); else { printf( "\nFrom MSDN page on _fstat():\n" " Get information about an open file.\n" " st_mode\n" " Bit mask for file-mode information.\n" " The _S_IFCHR bit is set if handle refers to a device.\n" " The _S_IFREG bit is set if handle refers to an ordinary file.\n" " The read/write bits are set according to the file's permission mode.\n" " _S_IFCHR and other constants are defined in SYS\\STAT.H.\n" ); printf( "Mode (oct) : 0%06o\n", (unsigned short)buf.st_mode ); printf( "Mode (hex) : 0x%04x\n", (unsigned short)buf.st_mode ); } } } #### stat() by _stat() fstat() by _fstat() struct stat by struct _stat