posix_mknod

Create a special or ordinary file (POSIX.1)

Description

bool posix_mknod(
    string $filename,
    int $flags,
    int $major = 0,
    int $minor = 0
)

Creates a special or ordinary file.

Parameters

filename

The file to create

flags

This parameter is constructed by a bitwise OR between file type (one of the following constants: POSIX_S_IFREG, POSIX_S_IFCHR, POSIX_S_IFBLK, POSIX_S_IFIFO or POSIX_S_IFSOCK) and permissions.

major

The major device kernel identifier (required to pass when using S_IFCHR or S_IFBLK).

minor

The minor device kernel identifier.

Return Values

Returns true on success or false on failure.

Examples

Example #1 A posix_mknod example

<?php

$file = '/tmp/tmpfile';  // file name
$type = POSIX_S_IFBLK;   // file type
$permissions = 0777;     // octal
$major = 1;
$minor = 8;              // /dev/random

if (!posix_mknod($file, $type | $permissions, $major, $minor)) {
    die('Error ' . posix_get_last_error() . ': ' . posix_strerror(posix_get_last_error()));
}

?>

See Also

  • posix_mkfifo