17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217257d1b4Sraf
227c478bd9Sstevel@tonic-gate /*
23*794f0adbSRoger A. Faulkner * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267257d1b4Sraf #include "lint.h"
277c478bd9Sstevel@tonic-gate #include <unistd.h>
28*794f0adbSRoger A. Faulkner #include <fcntl.h>
29*794f0adbSRoger A. Faulkner #include <sys/syscall.h>
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate extern int __xpg4; /* defined in port/gen/xpg4.c; 0 if not xpg4/xpg4v2 */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate int
linkat(int fd1,const char * path1,int fd2,const char * path2,int flag)34*794f0adbSRoger A. Faulkner linkat(int fd1, const char *path1, int fd2, const char *path2, int flag)
357c478bd9Sstevel@tonic-gate {
36*794f0adbSRoger A. Faulkner return (syscall(SYS_linkat, fd1, path1, fd2, path2, flag));
37*794f0adbSRoger A. Faulkner }
387c478bd9Sstevel@tonic-gate
39*794f0adbSRoger A. Faulkner #pragma weak _link = link
40*794f0adbSRoger A. Faulkner int
link(const char * path1,const char * path2)41*794f0adbSRoger A. Faulkner link(const char *path1, const char *path2)
42*794f0adbSRoger A. Faulkner {
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate * XPG4v2 link() requires that the link count of a symbolic
457c478bd9Sstevel@tonic-gate * link target be updated rather than the link itself. This
467c478bd9Sstevel@tonic-gate * matches SunOS 4.x and other BSD based implementations.
477c478bd9Sstevel@tonic-gate * However, the SVR4 merge apparently introduced the change
487c478bd9Sstevel@tonic-gate * that allowed link(src, dest) when "src" was a symbolic link,
497c478bd9Sstevel@tonic-gate * to create "dest" as a hard link to "src". Hence, the link
507c478bd9Sstevel@tonic-gate * count of the symbolic link is updated rather than the target
517c478bd9Sstevel@tonic-gate * of the symbolic link. This latter behavior remains for
527c478bd9Sstevel@tonic-gate * non-XPG4 based environments. For a more detailed discussion,
537c478bd9Sstevel@tonic-gate * see bug 1256170.
547c478bd9Sstevel@tonic-gate */
55*794f0adbSRoger A. Faulkner if (__xpg4 != 0)
56*794f0adbSRoger A. Faulkner return (linkat(AT_FDCWD, path1, AT_FDCWD, path2,
57*794f0adbSRoger A. Faulkner AT_SYMLINK_FOLLOW));
58*794f0adbSRoger A. Faulkner
59*794f0adbSRoger A. Faulkner #if defined(_RETAIN_OLD_SYSCALLS)
60*794f0adbSRoger A. Faulkner return (syscall(SYS_link, path1, path2));
61*794f0adbSRoger A. Faulkner #else
62*794f0adbSRoger A. Faulkner return (linkat(AT_FDCWD, path1, AT_FDCWD, path2, 0));
63*794f0adbSRoger A. Faulkner #endif
647c478bd9Sstevel@tonic-gate }
65