/* * Sample program for mknod() system call - No.14 * * mknod(2) - create a special or rodinary file * * Synopsis * #include * #include * #include * #include * * int mknod(const char *pathname, mode_t mode, dev_t dev); * Types * unsigned int mode_t ---- , * unsigned long long int dev_t ---- , * Macros * * #define __S_IFDIR 0040000 * Directory. * * #define __S_IFCHR 0020000 * Character device. * * #define __S_IFBLK 0060000 * Block device. * * #define __S_IFREG 0100000 * Regular file. * * #define __S_IFIFO 0010000 * FIFO. * * * # define S_IFMT __S_IFMT * # define S_IFDIR __S_IFDIR * # define S_IFCHR __S_IFCHR * # define S_IFBLK __S_IFBLK * # define S_IFREG __S_IFREG * # define S_IFIFO __S_IFIFO * * We need to know the word order here. This assumes that the word order is consistent with the byte order. * * # include * # if __BYTE_ORDER == __BIG_ENDIAN * # define major(dev) (((dev).__val[1] >> 8) & 0xff) * # define minor(dev) ((dev).__val[1] & 0xff) * # define makedev(major, minor) { 0, ((((unsigned int) (major)) << 8) \ * | ((unsigned int) (minor))) } * # else * # define major(dev) (((dev).__val[0] >> 8) & 0xff) * # define minor(dev) ((dev).__val[0] & 0xff) * # define makedev(major, minor) { ((((unsigned int) (major)) << 8) \ | ((unsigned int) (minor))), 0 } * # endif * #endif */ #include #include main() { /* make FIFO file */ mknod("foo", S_IFIFO | 0666, 0); exit(0); }