Next Previous Contents

52. mkdir


Create a new directory


Integer_Type mkdir (String_Type dir, Integer_Type mode)


The mkdir function creates a directory whose name is specified by the dir parameter with permissions specified by mode. Upon success mkdir returns zero, or it returns -1 and sets errno accordingly. In particular, if the directory already exists, the function will fail and set errno to EEXIST.


define my_mkdir (dir) { if (0 == mkdir (dir, 0777)) return; if (errno == EEXIST) return; verror ("mkdir %s failed: %s", dir, errno_string (errno)); }


The mode parameter may not be meaningful on all systems. On systems where it is meaningful, the actual permissions on the newly created directory are modified by the process's umask.

See Also

rmdir, getcwd, chdir, fopen, errno

Next Previous Contents