gtpc2m4t | C/C++ Language Support User's Guide |
This function creates a special file.
Format
#include <sys/stat.h> int mknod(const char *path, mode_t mode, rdev_t dev_identifier)
This function creates a new character special file with the path name specified in the path argument.
The mode argument determines the type of the special file and (along with the file creation mask) the file permissions of the special file. The TPF mknod function only supports the character type of special file: S_IFCHR. Bits set in the file creation mask are cleared in the file permissions. For more information about these symbols, see chmod-Change the Mode of a File or Directory.
The dev_identifier argument contains the major device number and the minor device number of the special file. The major device number identifies a device driver supporting a class of devices or pseudo devices such as input message devices. The minor device number identifies a specific device or pseudo device in the pertinent class.
When it has completed successfully, the mknod function updates the st_mtime field in the new file. It also updates the st_mtime field of the directory that contains the new file.
TPF deviation from POSIX |
---|
The TPF system does not support the atime (access time) or ctime (change time) time stamp. |
Normal Return
If successful, the mknod function returns a value of 0.
Error Return
If unsuccessful, the mknod function returns a value of -1 and sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Because the mknod function requires an update to an existing directory file, new character special files cannot be created in 1052 or UTIL state.
Examples
The following example provides status information for a file.
#include <sys/stat.h> #include <unistd.h> #include <stdio.h> #define master 0x00070000 main() { char fn[]="char.spec"; if (mknod(fn, S_IFCHR|S_IRUSR|S_IWUSR, master|0x0001) != 0 perror("mknod() error"); else if (unlink(fn) != 0) perror("unlink() error"); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.