3.3. Changing permissions on an existing IFS Object

The API that allows us to change the permissions of an IFS object is called "chmod", which stands for "change mode". Here's the C-language prototype for chmod(), along with my RPG equivalent:

      int chmod(const char *path, mode_t mode)                     

     D chmod           PR            10I 0 ExtProc('chmod')          
     D   path                          *   Value options(*string)    
     D   mode                        10U 0 Value                     
   

The "mode" parameter works exactly the same as the "mode" parameter on the open() API. You use the same bit-flags to assign permissions to the "owner", the "group" and "others".

The difference between chmod() and open() is that chmod() does not open or create a new file, but instead changes the access permissions on an existing IFS object.

For example, let's say that you had already run the example program from chapter 2 called "CH2RAWDTA", and you know that it wrote an object to disk called "littlepgm.com". But now, you decided that you didn't want Bill from Accounting to be able to download your program! Since it's already there, you'd want to remove "read" permissions from the object.

To do that, you'd do something like this:

     c                   if        chmod('/ifstest/littlepgm.com':        
     c                                 S_IRUSR + S_IWUSR + S_IXUSR) < 0   
     c                   callp     EscErrno(errno)
     c                   endif                                            
   

We assigned Read, Write and Execute authority to the file's owner, but we gave no authority to "the group" or to "others", so, Bill won't be able to read it.