Chapter Contents |
Previous |
Next |
link |
Portability: | POSIX.1 conforming, UNIX compatible |
SYNOPSIS | |
DESCRIPTION | |
RETURN VALUE | |
EXAMPLE | |
RELATED FUNCTIONS | |
SEE ALSO |
SYNOPSIS |
#include <unistd.h> int link(char *oldfile, char *newname);
DESCRIPTION |
link
creates a hard link to an existing USS file.
oldfile
is the existing file. If
oldfile
is a symbolic link, the link refers to the file that is referenced
by the pathname in the symbolic link.
newname
is the new pathname. If the old name is removed, the file continues
to exist with the new name. You cannot create a link to a directory.
Both
oldfile
and
newname
must specify USS HFS filenames. For
programs not compiled with the
posix
option,
style prefixes may be required. See File Naming Conventions for information on specifying USS filenames.
RETURN VALUE |
link
returns a 0 if it is successful;
link
increments
the link count that refers to the number of links to the file.
link
returns a -1 if it is not successful; the link count is
not incremented.
EXAMPLE |
This example uses
link
and
unlink
to change the name
of an HFS file. It differs from the
rename
function in two ways:
#include <sys/types.h> #include <unistd.h> #include <stdio.h> int chname(char *oldname, char *newname) { int rc; rc = link(oldname, newname); if (rc != 0) { perror("link error"); return -1; /* Go no further if the link fails. */ } /* The link worked. Now we can unlink the old name. */ rc = unlink(oldname); if (rc != 0) { perror("unlink error"); return -1; } return 0; }
RELATED FUNCTIONS |
SEE ALSO |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.