#include <unistd.h> int symlink(const char *path, const char *sl);
symlink
creates a symbolic link to an OpenEdition HFS file. The file
need not already exist. path
is the pathname of the file. sl
is the pathname to be assigned to the symbolic link.
When you call symlink
in a non-posix
-compiled application, the pathname and the link name
both are interpreted according to the normal rules for interpretation of
filenames. These names should include a style prefix if the default style
is not "hfs")
. Note that the style prefix is not actually
stored in the symbolic link.
symlink
returns 0 if it is successful and
- 1 if it is not successful.
errno
equal
to EXDEV
, indicating that links are not supported between file
systems, the second argument is created as a symbolic link instead.
/* This example must be compiled using the posix compiler option. */ #include <sys/types.h> #include <unistd.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> main(int argc, char *argv[]) { int rc; if (argc != 3) { fputs("Incorrect number of arguments.", stderr); exit(EXIT_FAILURE); } rc = link(argv[1], argv[2]); /* Try to make hard link. */ if (rc != 0) /* if link failed */ if (errno != EXDEV) { /* unexpected error */ perror("link error"); exit(EXIT_FAILURE); } else { /* Attempt symbolic link. */ rc = symlink(argv[1], argv[2]); if (rc != 0) { perror("symlink error"); exit(EXIT_FAILURE); } printf("%s was created as a symbolic link to %s.n", argv[2], argv[1]); } else printf("%s was created as a hard link to %s.n", argv[2], argv[1]); exit(EXIT_SUCCESS); }
link
, lstat
, readlink