3.7. Deleting IFS objects

You may have noticed that the IBM commands for working with the IFS frequently use the term "link." For example, the WRKLNK command ("Work with Links") is used to browse the IFS. The RMVLNK command ("Remove Link") is used to delete stream files.

You may be wondering "What's a link?"

To understand this, you need to make the distinction between the data that's stored in the file, and the file's name which shows up in the directory.

The data itself is called the "file". The name which you find in a directory is just a way of referring to that data. In essence, it's a link to the file.

In fact, it's possible to have more than one link to the same data. When that happens, the same file data may appear in more than one directory and/or under more than one different file name. Each one is considered a separate link, even though it's the same data.

When you remove a link to a stream file, the system will first remove the file name from the directory, and then it will check if this was the last link to the file. If the deleted link was the last link, the file's data will also be removed.

The API to delete a link is called "unlink()". And it's C-language prototype looks like this:

     int unlink(const char *path)
   

Can't be much simpler than that, can it? It accepts only one parameter, and it's a null-terminated character string. It returns an integer, which will be a 0 if the API was successful or a -1 if it failed.

Here's the corresponding RPG prototype:

     D unlink          PR            10I 0 ExtProc('unlink')                 
     D   path                          *   Value options(*string)            
   

So, if you wanted to delete the stream file called "littlepgm.com", you'd write code that looks like this:

     c                   if        unlink('/ifstest/littlepgm.com') < 0 
     c                   callp     EscErrno(errno)
     c                   endif