symlink()--Make Symbolic Link


  Syntax
 #include <unistd.h>

 int symlink(const char *pname, const char *slink);  
  Service Program Name: QP0LLIB1

  Default Public Authority: *USE

  Threadsafe: Conditional; see Usage Notes.

The symlink() function creates the symbolic link named by slink with the value specified by pname. File access checking is not performed on the file pname, and the file need not exist. In addition, a symbolic link can cross file system boundaries.

If slink names a symbolic link, symlink() fails with the [EEXIST] error.

A symbolic link path name is resolved in the following manner:

Any files and directories to which a symbolic link refers are checked for access permission.

symlink() sets the access, change, modification, and creation times for the new symbolic link. It also sets the change and modification times for the directory that contains the new symbolic link.


Parameters

pname
(Input) A pointer to the null-terminated value of the symbolic link.

The value of the symbolic link is assumed to be represented in the CCSID (coded character set identifier) currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

See QlgSymlink--Make Symbolic Link (using NLS-enabled path name) for a description and an example of supplying the pname in any CCSID.


slink
(Input) A pointer to the null-terminated name of the symbolic link to be created.

This parameter is assumed to be represented in the CCSID, language, and country or region currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

See QlgSymlink--Make Symbolic Link (using NLS-enabled path name) for a description and an example of supplying the slink in any CCSID.


Authorities

Note: Adopted authority is not used.

Authorization Required for symlink()

Object Referred to Authority Required errno
Each directory in the path name preceding the object to be created *X EACCES
Parent directory of object to be created *WX EACCES


Return Value

0
symlink() was successful.
-1
symlink() was not successful. The errno global variable is set to indicate the error.

Error Conditions

If symlink() is not successful, errno usually indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

Error condition Additional information
[EACCES]

If you are accessing a remote file through the Network File System, update operations to file permissions at the server are not reflected at the client until updates to data that is stored locally by the Network File System take place. (Several options on the Add Mounted File System (ADDMFS) command determine the time between refresh operations of local data.) Access to a remote file may also fail due to different mappings of user IDs (UID) or group IDs (GID) on the local and remote systems.

[EAGAIN]  
[EBADFID]  
[EBADNAME]  
[EBUSY]  
[ECONVERT]  
[EDAMAGE]  
[EEXIST]  
[EFAULT]  
[EFILECVT]  
[EINTR]  
[EINVAL]  
[EIO]  
[EISDIR]  
[ELOOP]  
[ENAMETOOLONG]  
[ENOENT]  
[ENOMEM]  
[ENOSPC]  
[ENOSYS]  
[ENOTAVAIL]  
[ENOTDIR]  
[ENOTSAFE]  
[ENOTSUP]  
[EPERM]  
[EROOBJ]  
[ESTALE]

If you are accessing a remote file through the Network File System, the file may have been deleted at the server.

[EUNKNOWN]  


Error Messages

The following messages may be sent from this function:

Message ID Error Message Text
CPE3418 E Possible APAR condition or hardware failure.
CPFA0D4 E File system error occurred. Error number &1.
CPF3CF2 E Error(s) occurred during running of &1 API.
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.

Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:
  2. The following file systems do not support symlink():


Related Information


Example

See Code disclaimer information for information pertaining to code examples.

The following example uses symlink():

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>

main() {
  char fn[]="readlink.file";
  char sl[]="readlink.symlink";
  char buf[30];
  int  file_descriptor;

  if ((file_descriptor = creat(fn, S_IWUSR)) < 0)
    perror("creat() error");
  else {
    close(file_descriptor);
    if (symlink(fn, sl) != 0)
      perror("symlink() error");
    else {
      if (readlink(sl, buf, sizeof(buf)) < 0)
        perror("readlink() error");
      else printf("readlink() returned '%s' for '%s'\n", buf, sl);

      unlink(sl);
    }
    unlink(fn);
  }
}

Output:

readlink() returned 'readlink.file' for 'readlink.symlink'


API introduced: V3R1
Top | UNIX-Type APIs | APIs by category