php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42705 Defining sys/stat.h's constants in PHP
Submitted: 2007-09-19 05:46 UTC Modified: -
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: arnaud dot lb at gmail dot com Assigned:
Status: Open Package: Feature/Change Request
PHP Version: 5.2.4 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-09-19 05:46 UTC] arnaud dot lb at gmail dot com
Description:
------------
It would be very useful to have the sys/stat.h constants (S_*, e.g. 
S_ISUID for the setuid bit) defined in PHP, to be able to more 
easily use the values returned by functions such as fileperms() or 
stat().

I actually use this to define them (from stat(2) man page), but I 
guess it's not portable:
<?php
define('S_IFMT',        0170000);       //bit mask for the file type 
bit fields
define('S_IFSOCK',      0140000);       //socket
define('S_IFLNK',       0120000);       //symbolic link
define('S_IFREG',       0100000);       //regular file
define('S_IFBLK',       0060000);       //block device
define('S_IFDIR',       0040000);       //directory
define('S_IFCHR',       0020000);       //character device
define('S_IFIFO',       0010000);       //FIFO
define('S_ISUID',       0004000);       //set UID bit
define('S_ISGID',       0002000);       //set-group-ID bit (see 
below)
define('S_ISVTX',       0001000);       //sticky bit (see below)
define('S_IRWXU',       00700); //mask for file owner permissions
define('S_IRUSR',       00400); //owner has read permission
define('S_IWUSR',       00200); //owner has write permission
define('S_IXUSR',       00100); //owner has execute permission
define('S_IRWXG',       00070); //mask for group permissions
define('S_IRGRP',       00040); //group has read permission
define('S_IWGRP',       00020); //group has write permission
define('S_IXGRP',       00010); //group has execute permission
define('S_IRWXO',       00007); //mask for permissions for others 
(not in group)
define('S_IROTH',       00004); //others have read permission
define('S_IWOTH',       00002); //others have write permission
define('S_IXOTH',       00001); //others have execute permission
?>

This make me able to do things like ($fileperms & S_IROTH) instead 
of ($fileperms & 00004) to know if a file is world readable.


Patches

Add a Patch

Pull Requests

Add a Pull Request

 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Dec 12 16:01:24 2019 UTC