7.2. Creating directories

The API for creating a new directory (or sub-directory) in the IFS is called "mkdir()." This stands, appropriately, for "make directory."

Here are the C language and RPG prototypes for the mkdir() API. They're straightforward, so I will not bore you with the conversion details,

     int mkdir(const char *path, mode_t mode)

     (1)D mkdir           PR            10I 0 ExtProc('mkdir')              
     (2)D   path                          *   Value options(*string)        
     (3)D   mode                        10U 0 Value                         
mkdir() returns -1 if it failed, or 0 if it was successful
The "path" parameter is where you specify the directory to be created. The format of the path is just like that specified in the open() API.
The "mode" parameter is the access permissions to assign to the directory when it's created. You specify the mode using the same bit-flags that you used for the mode on the open() API.

For example, consider the following code:

     C                   if        mkdir('/ifstest/ShoeTongue':         
     C                                  S_IRUSR+S_IWUSR+S_IXUSR+        
     C                                  S_IRGRP+S_IWGRP+S_IXGRP+        
     C                                  S_IROTH+S_IXOTH) < 0            
     C                   callp     EscErrno(errno)
     C                   endif                                          

This code creates a new sub-directory called "ShoeTongue" inside the a directory called "/ifstest". It grants read, write and search permissions to the owner, read, write and search permissions to the primary group, and read and search permissions to everyone else.

In order for this command to exist, the "/ifstest" directory must already exist. If not, the command will fail with "path or directory not found!"