Make a new filesystem entry point
#include <sys/types.h> #include <unistd.h> #include <sys/stat.h> int mknod( const char * path, mode_t mode, dev_t dev );
For more information, see “Access permissions” in the documentation for stat().
libc
Use the -l c option to qcc to link against this library. This library is usually included automatically.
The mknod() makes a file, named path, using the file type encoded in the mode argument. Supported file types are directories and FIFOs.
This function is included to enhance portability with software written for Unix-compatible operating systems. For POSIX portability, use mkdir() or mkfifo() instead. |
To make a directory with read-write-execute permissions for everyone, you could use the following:
mknod (name, S_IFDIR | 0777, 0);
/* * Create special files as a directory or FIFO */ #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> #include <unistd.h> int main( int argc, char** argv ) { int c; mode_t mode = 0666; int ecode = 0; if( argc == 1 ) { printf( "Use: %s [-d directory] ... [-f fifo] ... \n", argv[0] ); return( 0 ); } while(( c = getopt( argc, argv, "d:f:" )) != -1 ) { switch( c ) { case 'd': mode = S_IFDIR | 0666; break; case 'f': mode = S_IFIFO | 0666; break; } if( mknod( optarg, mode, 0 ) != 0 ) { perror( optarg ); ++ecode; } } return( ecode ); }
Safety: | |
---|---|
Cancellation point | Yes |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |