This source file includes following definitions.
- rpl_symlinkat
- symlinkat
- symlink_reversed
- symlinkat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include <unistd.h>
23
24 #include <errno.h>
25 #include <stdlib.h>
26
27 #if HAVE_SYMLINKAT
28 # undef symlinkat
29
30 #include <fcntl.h>
31 #include <sys/stat.h>
32 #include <string.h>
33
34
35 int
36 rpl_symlinkat (char const *contents, int fd, char const *name)
37 {
38 size_t len = strlen (name);
39 if (len && name[len - 1] == '/')
40 {
41 struct stat st;
42 if (fstatat (fd, name, &st, AT_SYMLINK_NOFOLLOW) == 0
43 || errno == EOVERFLOW)
44 errno = EEXIST;
45 return -1;
46 }
47 return symlinkat (contents, fd, name);
48 }
49
50 #elif !HAVE_SYMLINK
51
52
53
54 int
55 symlinkat (_GL_UNUSED char const *path1, _GL_UNUSED int fd,
56 _GL_UNUSED char const *path2)
57 {
58 errno = ENOSYS;
59 return -1;
60 }
61
62 #else
63
64
65
66
67
68 static int
69 symlink_reversed (char const *file, char const *contents)
70 {
71 return symlink (contents, file);
72 }
73
74
75
76 static int
77 symlinkat_reversed (int fd, char const *file, char const *contents);
78
79 # define AT_FUNC_NAME symlinkat_reversed
80 # define AT_FUNC_F1 symlink_reversed
81 # define AT_FUNC_POST_FILE_PARAM_DECLS , char const *contents
82 # define AT_FUNC_POST_FILE_ARGS , contents
83 # include "at-func.c"
84 # undef AT_FUNC_NAME
85 # undef AT_FUNC_F1
86 # undef AT_FUNC_POST_FILE_PARAM_DECLS
87 # undef AT_FUNC_POST_FILE_ARGS
88
89
90
91
92
93
94
95 int
96 symlinkat (char const *contents, int fd, char const *file)
97 {
98 return symlinkat_reversed (fd, file, contents);
99 }
100
101 #endif