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()



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 Messages

The following messages may be sent from this function:


Usage Notes

  1. This function will fail with error code [ENOTSAFE] when all the following conditions are true:
    • Where multiple threads exist in the job.
    • The object on which this function is operating resides in a file system that is not threadsafe. Only the following file systems are threadsafe for this function:
      • "Root" (/)
      • QOpenSys
      • User-defined
      • QNTC
      • QSYS.LIB
      • Independent ASP QSYS.LIB
      • QOPT
      • Network File System
      • QFileSvr.400

  2. The following file systems do not support symlink():

    • QSYS.LIB
    • Independent ASP QSYS.LIB
    • QDLS
    • QOPT
    • QFileSvr.400
    • QNTC

Related Information


Example

The following example uses symlink().

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#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

[ Back to top | UNIX-Type APIs | APIs by category ]