annotate lib/linkat.c @ 17249:e542fd46ad6f

maint: update all copyright year number ranges Run "make update-copyright". Compare to commit 1602f0a from last year. Signed-off-by: Eric Blake <eblake@redhat.com>
author Eric Blake <eblake@redhat.com>
date Tue, 01 Jan 2013 00:50:58 +0000 (2013-01-01)
parents 8250f2777afc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
1 /* Create a hard link relative to open directories.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 (at your option) any later version.
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 GNU General Public License for more details.
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
13
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
16
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
17 /* written by Eric Blake */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
18
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
19 #include <config.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
20
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
21 #include <unistd.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
22
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
23 #include <errno.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
24 #include <fcntl.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
25 #include <limits.h>
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
26 #include <stdlib.h>
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
27 #include <string.h>
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
28 #include <sys/stat.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
29
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
30 #include "areadlink.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
31 #include "dirname.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
32 #include "filenamecat.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
33 #include "openat-priv.h"
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
34
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
35 #if HAVE_SYS_PARAM_H
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
36 # include <sys/param.h>
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
37 #endif
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
38 #ifndef MAXSYMLINKS
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
39 # ifdef SYMLOOP_MAX
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
40 # define MAXSYMLINKS SYMLOOP_MAX
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
41 # else
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
42 # define MAXSYMLINKS 20
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
43 # endif
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
44 #endif
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
45
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
46 #if !HAVE_LINKAT
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
47
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
48 /* Create a link. If FILE1 is a symlink, either create a hardlink to
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
49 that symlink, or fake it by creating an identical symlink. */
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
50 # if LINK_FOLLOWS_SYMLINKS == 0
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
51 # define link_immediate link
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
52 # else
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
53 static int
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 link_immediate (char const *file1, char const *file2)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
55 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
56 char *target = areadlink (file1);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
57 if (target)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
58 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
59 /* A symlink cannot be modified in-place. Therefore, creating
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
60 an identical symlink behaves like a hard link to a symlink,
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 except for incorrect st_ino and st_nlink. However, we must
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
62 be careful of EXDEV. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
63 struct stat st1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
64 struct stat st2;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 char *dir = mdir_name (file2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
66 if (!dir)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
67 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
68 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
69 errno = ENOMEM;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
70 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
72 if (lstat (file1, &st1) == 0 && stat (dir, &st2) == 0)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
73 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
74 if (st1.st_dev == st2.st_dev)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
75 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
76 int result = symlink (target, file2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
77 int saved_errno = errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
78 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
79 free (dir);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
80 errno = saved_errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
81 return result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
82 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
83 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
84 free (dir);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
85 errno = EXDEV;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
86 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
87 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
88 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
89 free (dir);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
90 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
91 if (errno == ENOMEM)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
92 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
93 return link (file1, file2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
94 }
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
95 # endif /* LINK_FOLLOWS_SYMLINKS == 0 */
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
96
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
97 /* Create a link. If FILE1 is a symlink, create a hardlink to the
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
98 canonicalized file. */
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
99 # if 0 < LINK_FOLLOWS_SYMLINKS
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
100 # define link_follow link
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
101 # else
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
102 static int
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
103 link_follow (char const *file1, char const *file2)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
104 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
105 char *name = (char *) file1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
106 char *target;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
107 int result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
108 int i = MAXSYMLINKS;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
109
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
110 /* Using realpath or canonicalize_file_name is too heavy-handed: we
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
111 don't need an absolute name, and we don't need to resolve
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
112 intermediate symlinks, just the basename of each iteration. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
113 while (i-- && (target = areadlink (name)))
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
114 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
115 if (IS_ABSOLUTE_FILE_NAME (target))
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
116 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
117 if (name != file1)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
118 free (name);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
119 name = target;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
120 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
121 else
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
122 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
123 char *dir = mdir_name (name);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
124 if (name != file1)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
125 free (name);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
126 if (!dir)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
127 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
128 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
129 errno = ENOMEM;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
130 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
131 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
132 name = mfile_name_concat (dir, target, NULL);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
133 free (dir);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
134 free (target);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
135 if (!name)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
136 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
137 errno = ENOMEM;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
138 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
139 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
140 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
141 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
142 if (i < 0)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
143 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
144 target = NULL;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
145 errno = ELOOP;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
146 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
147 if (!target && errno != EINVAL)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
148 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
149 if (name != file1)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
150 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
151 int saved_errno = errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
152 free (name);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
153 errno = saved_errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
154 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
155 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
156 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
157 result = link (name, file2);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
158 if (name != file1)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
159 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
160 int saved_errno = errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
161 free (name);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
162 errno = saved_errno;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
163 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
164 return result;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
165 }
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
166 # endif /* 0 < LINK_FOLLOWS_SYMLINKS */
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
167
14050
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
168 /* On Solaris, link() doesn't follow symlinks by default, but does so as soon
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
169 as a library or executable takes part in the program that has been compiled
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
170 with "c99" or "cc -xc99=all" or "cc ... /usr/lib/values-xpg4.o ...". */
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
171 # if LINK_FOLLOWS_SYMLINKS == -1
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
172
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
173 /* Reduce the penalty of link_immediate and link_follow by incorporating the
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
174 knowledge that link()'s behaviour depends on the __xpg4 variable. */
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
175 extern int __xpg4;
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
176
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
177 static int
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
178 solaris_optimized_link_immediate (char const *file1, char const *file2)
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
179 {
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
180 if (__xpg4 == 0)
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
181 return link (file1, file2);
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
182 return link_immediate (file1, file2);
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
183 }
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
184
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
185 static int
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
186 solaris_optimized_link_follow (char const *file1, char const *file2)
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
187 {
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
188 if (__xpg4 != 0)
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
189 return link (file1, file2);
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
190 return link_follow (file1, file2);
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
191 }
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
192
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
193 # define link_immediate solaris_optimized_link_immediate
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
194 # define link_follow solaris_optimized_link_follow
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
195
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
196 # endif
6566818713fe linkat: Make implementation robust against system behaviour variations.
Bruno Haible <bruno@clisp.org>
parents: 13514
diff changeset
197
12068
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
198 /* Create a link to FILE1, in the directory open on descriptor FD1, to FILE2,
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
199 in the directory open on descriptor FD2. If FILE1 is a symlink, FLAG
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
200 controls whether to dereference FILE1 first. If possible, do it without
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
201 changing the working directory. Otherwise, resort to using
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
202 save_cwd/fchdir, then rename/restore_cwd. If either the save_cwd or
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
203 the restore_cwd fails, then give a diagnostic and exit nonzero. */
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
204
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
205 int
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
206 linkat (int fd1, char const *file1, int fd2, char const *file2, int flag)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
207 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
208 if (flag & ~AT_SYMLINK_FOLLOW)
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
209 {
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
210 errno = EINVAL;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
211 return -1;
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
212 }
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
213 return at_func2 (fd1, file1, fd2, file2,
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
214 flag ? link_follow : link_immediate);
14cddb59cb05 linkat: new module
Eric Blake <ebb9@byu.net>
parents:
diff changeset
215 }
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
216
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
217 #else /* HAVE_LINKAT */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
218
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
219 # undef linkat
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
220
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
221 /* Create a link. If FILE1 is a symlink, create a hardlink to the
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
222 canonicalized file. */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
223
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
224 static int
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
225 linkat_follow (int fd1, char const *file1, int fd2, char const *file2)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
226 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
227 char *name = (char *) file1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
228 char *target;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
229 int result;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
230 int i = MAXSYMLINKS;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
231
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
232 /* There is no realpathat. */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
233 while (i-- && (target = areadlinkat (fd1, name)))
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
234 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
235 if (IS_ABSOLUTE_FILE_NAME (target))
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
236 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
237 if (name != file1)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
238 free (name);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
239 name = target;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
240 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
241 else
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
242 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
243 char *dir = mdir_name (name);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
244 if (name != file1)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
245 free (name);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
246 if (!dir)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
247 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
248 free (target);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
249 errno = ENOMEM;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
250 return -1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
251 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
252 name = mfile_name_concat (dir, target, NULL);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
253 free (dir);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
254 free (target);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
255 if (!name)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
256 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
257 errno = ENOMEM;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
258 return -1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
259 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
260 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
261 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
262 if (i < 0)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
263 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
264 target = NULL;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
265 errno = ELOOP;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
266 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
267 if (!target && errno != EINVAL)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
268 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
269 if (name != file1)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
270 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
271 int saved_errno = errno;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
272 free (name);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
273 errno = saved_errno;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
274 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
275 return -1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
276 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
277 result = linkat (fd1, name, fd2, file2, 0);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
278 if (name != file1)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
279 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
280 int saved_errno = errno;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
281 free (name);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
282 errno = saved_errno;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
283 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
284 return result;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
285 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
286
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
287
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
288 /* Like linkat, but guarantee that AT_SYMLINK_FOLLOW works even on
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
289 older Linux kernels. */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
290
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
291 int
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
292 rpl_linkat (int fd1, char const *file1, int fd2, char const *file2, int flag)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
293 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
294 if (flag & ~AT_SYMLINK_FOLLOW)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
295 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
296 errno = EINVAL;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
297 return -1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
298 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
299
14379
2330aac2ae54 maint: adjust cpp indentation to reflect nesting depth
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
300 # if LINKAT_TRAILING_SLASH_BUG
13514
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
301 /* Reject trailing slashes on non-directories. */
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
302 {
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
303 size_t len1 = strlen (file1);
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
304 size_t len2 = strlen (file2);
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
305 if ((len1 && file1[len1 - 1] == '/')
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
306 || (len2 && file2[len2 - 1] == '/'))
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
307 {
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
308 /* Let linkat() decide whether hard-linking directories is legal.
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
309 If fstatat() fails, then linkat() should fail for the same reason;
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
310 if fstatat() succeeds, require a directory. */
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
311 struct stat st;
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
312 if (fstatat (fd1, file1, &st, flag ? 0 : AT_SYMLINK_NOFOLLOW))
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
313 return -1;
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
314 if (!S_ISDIR (st.st_mode))
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
315 {
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
316 errno = ENOTDIR;
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
317 return -1;
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
318 }
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
319 }
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
320 }
14379
2330aac2ae54 maint: adjust cpp indentation to reflect nesting depth
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
321 # endif
13514
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
322
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
323 if (!flag)
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
324 return linkat (fd1, file1, fd2, file2, flag);
6154fce586b6 linkat: Work around AIX 7.1 bug.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
325
12120
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
326 /* Cache the information on whether the system call really works. */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
327 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
328 static int have_follow_really; /* 0 = unknown, 1 = yes, -1 = no */
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
329 if (0 <= have_follow_really)
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
330 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
331 int result = linkat (fd1, file1, fd2, file2, flag);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
332 if (!(result == -1 && errno == EINVAL))
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
333 {
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
334 have_follow_really = 1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
335 return result;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
336 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
337 have_follow_really = -1;
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
338 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
339 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
340 return linkat_follow (fd1, file1, fd2, file2);
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
341 }
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
342
0bc26baea4bf linkat: support Linux 2.6.17
Eric Blake <ebb9@byu.net>
parents: 12068
diff changeset
343 #endif /* HAVE_LINKAT */