Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 17 additions & 33 deletions reference/filesystem/functions/fileperms.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<!-- EN-Revision: 871a231f4a1caa5fb258ae53b1bb7d1fb2a0f949 Maintainer: PhilDaiguille Status: ready -->
<!-- EN-Revision: f5c4950be0ef12e84eea5276b15a7d143885286c Maintainer: PhilDaiguille Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.fileperms" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
Expand Down Expand Up @@ -90,51 +90,35 @@ echo substr(sprintf('%o', fileperms('/etc/passwd')), -4);
$perms = fileperms('/etc/passwd');

switch ($perms & 0xF000) {
case 0xC000: // Socket
$info = 's';
break;
case 0xA000: // Enlace simbólico
$info = 'l';
break;
case 0x8000: // Regular
$info = 'r';
break;
case 0x6000: // Especial de bloque
$info = 'b';
break;
case 0x4000: // Directorio
$info = 'd';
break;
case 0x2000: // Especial de carácter
$info = 'c';
break;
case 0x1000: // Pipe FIFO
$info = 'p';
break;
default: // Desconocido
$info = 'u';
case 0x1000: $info = 'p'; break; // Pipe FIFO
case 0x2000: $info = 'c'; break; // Especial de carácter
case 0x4000: $info = 'd'; break; // Directorio
case 0x6000: $info = 'b'; break; // Especial de bloque
case 0x8000: $info = '-'; break; // Regular
case 0xA000: $info = 'l'; break; // Enlace simbólico (accesible al utilizar la función lstat)
case 0xC000: $info = 's'; break; // Socket

// Desconocido
default: $info = 'u';
}

// Propietario
$setuid = $perms & 0x0800;
$info .= (($perms & 0x0100) ? 'r' : '-');
$info .= (($perms & 0x0080) ? 'w' : '-');
$info .= (($perms & 0x0040) ?
(($perms & 0x0800) ? 's' : 'x' ) :
(($perms & 0x0800) ? 'S' : '-'));
$info .= (($perms & 0x0040) ? ($setuid ? 's' : 'x') : ($setuid ? 'S' : '-'));

// Grupo
$setgid = $perms & 0x0400;
$info .= (($perms & 0x0020) ? 'r' : '-');
$info .= (($perms & 0x0010) ? 'w' : '-');
$info .= (($perms & 0x0008) ?
(($perms & 0x0400) ? 's' : 'x' ) :
(($perms & 0x0400) ? 'S' : '-'));
$info .= (($perms & 0x0008) ? ($setgid ? 's' : 'x') : ($setgid ? 'S' : '-'));

// Todos
$sticky = $perms & 0x0200;
$info .= (($perms & 0x0004) ? 'r' : '-');
$info .= (($perms & 0x0002) ? 'w' : '-');
$info .= (($perms & 0x0001) ?
(($perms & 0x0200) ? 't' : 'x' ) :
(($perms & 0x0200) ? 'T' : '-'));
$info .= (($perms & 0x0001) ? ($sticky ? 't' : 'x') : ($sticky ? 'T' : '-'));

echo $info;
?>
Expand Down