gtpc2m4r | C/C++ Language Support User's Guide |
This function creates a directory.
Format
#include <sys/stat.h> int mkdir(char *pathname, mode_t mode);
This function creates a new, empty directory called pathname. The file permission bits in mode are modified by the file creation mask of the process and then used to set the file permission bits of the directory being created. For more information about the file creation mask, see umask-Set the File Mode Creation Mask; for information about the file permission bits, see chmod-Change the Mode of a File or Directory.
If the S_ISGID mode bit is set OFF in the parent directory, the group ID of the new directory is set to the group ID of the process; otherwise, the group ID of the new directory is set to the group ID of the parent directory.
The mkdir function sets the modification time for the new directory. It also sets the modification time for the directory that contains the new directory.
TPF deviation from POSIX |
---|
The TPF system does not support the atime (access time) or ctime (change time) time stamp. |
If pathname names a symbolic link, mkdir fails.
Normal Return
If successful, the mkdir function returns a value of 0.
Error Return
If unsuccessful, the mkdir function does not create a directory; it returns a value of -1 and sets errno to one of the following:
Programming Considerations
The TPF system does not support creating, updating, or deleting files in 1052 or UTIL state. Special files may or may not be writable in 1052 or UTIL state depending on the device driver implementation.
Because the mkdir function requires an update to an existing directory file and the creation of a new directory file, new directories cannot be created in 1052 or UTIL state.
Examples
The following example creates a new directory.
#include <sys/stat.h> #include <unistd.h> #include <stdio.h> main() { char new_dir[]="new.dir"; if (mkdir(new_dir, S_IRWXU|S_IRGRP|S_IXGRP) != 0) perror("mkdir() error"); else if (chdir(new_dir) != 0) perror("first chdir() error"); else if (chdir("..") != 0) perror("second chdir() error"); else if (rmdir(new_dir) != 0) perror("rmdir() error"); else puts("success!"); }
Related Information
See Appendix E, Programming Support for the TPF File System for more information about TPF File System C Functions.