note 54999 added to function.stat

From: Date: Fri, 22 Jul 2005 01:06:15 +0000
Subject: note 54999 added to function.stat
Groups: php.notes 
Request: Send a blank email to php-notes+get-92269@lists.php.net to get a copy of this message
Re note posted by "salisbm at hotmail dot com": S_IFDIR is not a single-bit flag. It is a constant that relies on the "S_IFMT" bitmask. This bitmask should be applied to the "mode" parameter before comparing with any of the other "S_IF..." constants, as indicated by stat.h: #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) That is, this approach is incorrect: <?php define('S_IFDIR',040000); if ($mode & S_IFDIR) { /* incorrect! format could be S_IFDIR, but also S_IFBLK, S_IFSOCK, or S_IFWHT. */ } ?> ...and should instead be: <?php define('S_IFMT',0170000); define('S_IFDIR',040000); if (S_IFDIR == ($mode & S_IFMT)) { /* ... */ } ?> As pointed out by "svend at svendtofte dot com", however, there is also the "is_dir" function for this purpose, along with "is_file" and "is_link" to cover the most common format types... ---- Manual Page -- http://www.php.net/manual/en/function.stat.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54999 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54999&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54999&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92269) next »