Chapter Contents

Previous

Next
mknod

mknod



Create a Character or FIFO Special File

Portability: SAS/C extension


SYNOPSIS
DESCRIPTION
RETURN VALUE
PORTABILITY
EXAMPLE
RELATED FUNCTIONS


SYNOPSIS

#include <sys/stat.h>

int mknod(const char *path, mode_t mode, rdev_t device_id);


DESCRIPTION

mknod creates a new character special file or a FIFO special file. The path argument specifies the pathname of the special file, and the mode argument determines which type of special file is created. The following symbols can be specified as the mode argument:
S_IFCHR Character special file
S_IFFIFO FIFO special file

A character special file is usually associated with a device, and a FIFO (first-in-first-out) special file is a named pipe that is used for communciation between two processes.

The file permissions bits of the new special file can also be initialized with the mode argument. To do this, use a bitwise OR operation to combine any of the permissions symbols described for the mode argument of the chmod function with either S_IFCHR or S_IFFIFO .

The device_id argument identifies the specific device associated with a character special file. This argument is not used with FIFO special files.

The device_id argument is one word long, with the high-order 16 bits used to identify the device driver for a class of devices, such as interactive terminals. See IBM's Application Callable Services for OpenEdition MVS (SC23-3020) for an explanation of device IDs.


RETURN VALUE

mknod returns 0 if successful and -1 if it is unsuccessful.


PORTABILITY

The mknode function is useful in POSIX applications; however, it is not defined by POSIX.1 and should not be used in strictly conforming applications. POSIX.1 does not provide a way to make character special files.


EXAMPLE

The following code fragment illustrates the use of mknod to create a character special file with user read and write permissions set and a device_id of 0x00020003 . (It is a slave pseudo TTY.)

#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>

#define deviceClass 0x00020000
#define ttyNumber 3
.
.
.
char charSpecial[]="pseudo.tty";
.
.
.
mknod(charSpecial, S_IFCHR|S_RUSR|S_IWUSR, deviceClass|ttyNumber);
.
.
.


RELATED FUNCTIONS

mkfifo


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.