extlink_np() — Create an external symbolic link

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#include <unistd.h>

int extlink_np(const char *ename, const char *elink);

General description

Creates the external symbolic link file named by elink with the object specified by ename. The ename is not resolved, and refers to an object outside the HFS (hierarchical file system). The variable elink is the name of the external symbolic link file created, and ename is the name of the object contained within that file.

Returned value

If successful, extlink_np() returns 0.

If unsuccessful, extlink_np() returns -1, does not affect any file it names, and sets errno to one of the following values:
Error Code
Description
EACCES
A component of the elink path prefix denies search permission.
EEXIST
The file named by elink already exists.
EINVAL
elink has a slash as its last component, which indicates that the preceding component will be a directory. An external link cannot be a directory.
ELOOP
A loop exists in symbolic links. This error is issued if the number of symbolic links encountered during resolution of the elink argument is greater than POSIX_SYMLOOP.
ENAMETOOLONG
pathname is longer than PATH_MAX characters, or some component of pathname is longer than NAME_MAX characters while _POSIX_NO_TRUNC is in effect. For symbolic links, the length of the pathname string substituted for a symbolic link exceeds PATH_MAX. The PATH_MAX and NAME_MAX values can be determined with pathconf().
ENOTDIR
A component of the path prefix of elink is not a directory.
ENOSPC
The new external link cannot be created because there is no space left on the file system to contain it.
EROFS
The file named by elink cannot be created on a read-only file system.

Example

CELEBE07
⁄* CELEBE07                                      

   This example creates an external symbolic link.                              
                                                                                
 *⁄                                                                             
#include <stdio.h>                                                              
#include <fcntl.h>                                                              
#include <errno.h>                                                              
#include <unistd.h>                                                             
#include <stdlib.h>                                                             
#include <sys⁄stat.h>                                                           
#include <sys⁄types.h>                                                          
                                                                                
main( argc, argv )                                                              
  int   argc ;                                                                  
  char  *argv ;                                                                 
{                                                                               
  int   i_rc ;                                                                  
  int   i_fd ;                                                                  
  char  ac_mvsds[] = "SYS1.LINKLIB" ;                                           
  char  ac_mvsdsextsymlnk[] = "sys1.linklib.extsymlink" ;                       
                                                                                
  i_rc = unlink( ac_mvsdsextsymlnk ) ;                                          
                                                                                
  if (( i_rc == -1 ) && ( errno == ENOENT )) {                                  
  }                                                                             
  else                                                                          
  {                                                                             
    perror( "unlink() error" ) ;                                                
    return( -1 ) ;                                                              
  }                                                                             
                                                                                
  printf( "Before extlink_np() call ...\n" ) ;                                  
  system( "ls -il sys1.*" ) ;                                                   
                                                                                
  i_rc = extlink_np( ac_mvsds, ac_mvsdsextsymlnk ) ;                            
                                                                                
  if ( i_rc == -1 )                                                             
  {                                                                             
    perror( "extlink_np() error" ) ;                                            
    return( -1 ) ;                                                              
  }                                                                             
                                                                                
  printf( "After extlink_np() call ...\n" ) ;                                   
  system( "ls -il sys1.*" ) ;                                                   
                                                                                
  i_rc = unlink( ac_mvsdsextsymlnk ) ;                                          
}                                                                               

Related information