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