Merge commit '281819e5f8b19cd8627541a22d261906fd190276' into merges
[unleashed.git] / usr / src / lib / libc / port / sys / link.c
blobe13a4bc282b7f433a5c09e3465e68e4b0db8a6ed
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
26 #include "lint.h"
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <sys/syscall.h>
31 extern int __xpg4; /* defined in port/gen/xpg4.c; 0 if not xpg4/xpg4v2 */
33 int
34 linkat(int fd1, const char *path1, int fd2, const char *path2, int flag)
36 return (syscall(SYS_linkat, fd1, path1, fd2, path2, flag));
39 #pragma weak _link = link
40 int
41 link(const char *path1, const char *path2)
44 * XPG4v2 link() requires that the link count of a symbolic
45 * link target be updated rather than the link itself. This
46 * matches SunOS 4.x and other BSD based implementations.
47 * However, the SVR4 merge apparently introduced the change
48 * that allowed link(src, dest) when "src" was a symbolic link,
49 * to create "dest" as a hard link to "src". Hence, the link
50 * count of the symbolic link is updated rather than the target
51 * of the symbolic link. This latter behavior remains for
52 * non-XPG4 based environments. For a more detailed discussion,
53 * see bug 1256170.
55 return (linkat(AT_FDCWD, path1, AT_FDCWD, path2,
56 (__xpg4 != 0) ? AT_SYMLINK_FOLLOW : 0));