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: 2020-04-08 10:37 UTC
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: *General Issues
PHP Version: 5.2.4 OS:
Private report: No CVE-ID: None
 [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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-04-08 10:37 UTC] cmb@php.net
-Package: Feature/Change Request +Package: *General Issues
 [2020-04-08 10:37 UTC] cmb@php.net
The S_IF* constants are already available in the posix extension
as of PHP 5.1.0[1].

[1] <https://www.php.net/manual/en/posix.constants.mknod.php>
 [2024-01-26 06:20 UTC] ameliabrnnr at gmail dot com
Thank you so much for the informative and interesting post. (https://github.com)(https://www.skywardfbisd.online/)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC