![]() |
![]() |
![]() |
Create a subdirectory
#include <sys/types.h> #include <sys/stat.h> int mkdir( const char *path, mode_t mode );
libc
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 new directory is created with file permissions matching mode, modified by the process's file creation mask (see umask()). The access permissions for the file or directory are specified as a combination of bits defined in the <sys/stat.h> header file.
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()
![]() |
![]() |
![]() |