![]() |
![]() |
![]() |
![]() |
Create a subdirectory
#include <sys/types.h> #include <sys/stat.h> int mkdir( const char *path, mode_t mode );
The access permissions for the file or directory are specified as a combination of bits defined in the <sys/stat.h> header file. 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 mkdir() function creates a new subdirectory named path. The path can be relative to the current working directory or it can be an absolute path name.
![]() |
Not all filesystems support the creation of directories. For example, /dev/shmem (which really isn't a filesystem but looks like one) doesn't. For more information, see the Working with Filesystems chapter of the QNX Neutrino User's Guide. |
The directory's owner ID is set to the process's effective user ID. The directory's group ID is set to the group ID of the parent directory (if the parent set-group ID bit is set) or to the process's effective group ID.
The newly created directory is empty.
The following bits, in addition to file permission bits, behave as follows:
The mkdir() function marks the st_atime, st_ctime, and st_mtime fields of the directory for update. Also, the st_ctime and st_mtime fields of the parent directory are also updated.
0, or -1 if an error occurs (errno is set).
To make a new directory called /src in /hd:
#include <sys/types.h> #include <sys/stat.h> #include <stdlib.h> int main( void ) { (void)mkdir( "/hd/src", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH ); return EXIT_SUCCESS; }
Safety: | |
---|---|
Cancellation point | No |
Interrupt handler | No |
Signal handler | Yes |
Thread | Yes |
chdir(), chmod(), errno, fchdir(), getcwd(), mknod(), rmdir(), stat(), umask()
![]() |
![]() |
![]() |
![]() |