PHP Conference Japan 2024

posix_mknod

(PHP 5 >= 5.1.0, PHP 7, PHP 8)

posix_mknod 建立特殊或一般檔案 (POSIX.1)

描述

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

建立特殊或一般檔案。

參數

filename

要建立的檔案

flags

此參數由檔案型別(以下常數之一:POSIX_S_IFREGPOSIX_S_IFCHRPOSIX_S_IFBLKPOSIX_S_IFIFOPOSIX_S_IFSOCK)與權限之間的位元 OR 運算構成。

major

主裝置核心識別碼(使用 S_IFCHRS_IFBLK 時必須傳遞)。

minor

次裝置核心識別碼。

傳回值

成功時返回 true,失敗時返回 false

範例

範例 #1 posix_mknod() 範例

<?php

$file
= '/tmp/tmpfile'; // 檔名
$type = POSIX_S_IFBLK; // 檔案型別
$permissions = 0777; // 八進位
$major = 1;
$minor = 8; // /dev/random

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

?>

參見

新增註解

使用者貢獻註解

此頁面尚無使用者貢獻的註解。
To Top