Standards / Extensions | C or C++ | Dependencies |
---|---|---|
XPG4.2 |
both |
#define _OPEN_SYS
#include <sys/stat.h>
int mknod(const char *path, mode_t mode, rdev_t dev_identifier);
#define _XOPEN_SOURCE_EXTENDED 1
#include <sys/stat.h>
int mknod(const char *path, mode_t mode, dev_t dev_identifier);
Creates a new directory, regular file, character special file, or FIFO special file (named pipe), with the pathname specified in the path argument.
The file permission bits of the new file are initialized with the remaining bits in mode and changed by the file creation mask of the process. For more information on these symbols, refer to chmod() — Change the mode of a file or directory.
Device major numbers 1,2 and 7: The device minor numbers range between 0 and one less than the maximum number of pseudoterminal pairs defined by the installation.
Device major numbers 3,4,6,8 and 9: The device minor number is ignored.
Device major number 5: The device minor number value represents the file descriptor to be referred to. For example, device minor 0 refers to file descriptor 0.
When it completes successfully, mknod() marks for update the following fields of the file: st_atime, st_ctime, and st_mtime. It also marks for update the st_ctime and st_mtime fields of the directory that contains the new file.
If successful, mknod() returns 0.
⁄* CELEBM18 *⁄
#include <sys⁄stat.h>
#include <unistd.h>
#include <stdio.h>
#define master 0x00010000
main() {
char fn[]="char ec";
if (mknod(fn, S_IFCHR|S_IRUSR|S_IWUSR, master|0x0001) != 0)
perror("mknod() error");
else if (unlink(fn) != 0)
perror("unlink() error");
}