This version of this document is no longer maintained. For the latest documentation, see http://www.qnx.com/developers/docs. |
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.
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 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, getcwd(), mknod(), rmdir(), stat(), umask()