]> git.cworth.org Git - tar/blob - gnu/symlinkat.c
Imported Upstream version 1.24
[tar] / gnu / symlinkat.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Create a symlink relative to an open directory.
4    Copyright (C) 2009-2010 Free Software Foundation, Inc.
5
6    This program is free software: you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
18
19 /* written by Eric Blake */
20
21 #include <config.h>
22
23 #include <unistd.h>
24
25 #if !HAVE_SYMLINK
26 /* Mingw lacks symlink, and it is more efficient to provide a trivial
27    wrapper than to go through at-func.c to call rpl_symlink.  */
28
29 # include <errno.h>
30
31 int
32 symlinkat (char const *path1 _GL_UNUSED, int fd _GL_UNUSED,
33            char const *path2 _GL_UNUSED)
34 {
35   errno = ENOSYS;
36   return -1;
37 }
38
39 #else /* HAVE_SYMLINK */
40
41 /* Our openat helper functions expect the directory parameter first,
42    not second.  These shims make life easier.  */
43
44 /* Like symlink, but with arguments reversed.  */
45 static int
46 symlink_reversed (char const *file, char const *contents)
47 {
48   return symlink (contents, file);
49 }
50
51 /* Like symlinkat, but with arguments reversed.  */
52
53 static int
54 symlinkat_reversed (int fd, char const *file, char const *contents);
55
56 # define AT_FUNC_NAME symlinkat_reversed
57 # define AT_FUNC_F1 symlink_reversed
58 # define AT_FUNC_POST_FILE_PARAM_DECLS , char const *contents
59 # define AT_FUNC_POST_FILE_ARGS        , contents
60 # include "at-func.c"
61 # undef AT_FUNC_NAME
62 # undef AT_FUNC_F1
63 # undef AT_FUNC_POST_FILE_PARAM_DECLS
64 # undef AT_FUNC_POST_FILE_ARGS
65
66 /* Create a symlink FILE, in the directory open on descriptor FD,
67    holding CONTENTS.  If possible, do it without changing the
68    working directory.  Otherwise, resort to using save_cwd/fchdir,
69    then symlink/restore_cwd.  If either the save_cwd or the restore_cwd
70    fails, then give a diagnostic and exit nonzero.  */
71
72 int
73 symlinkat (char const *contents, int fd, char const *file)
74 {
75   return symlinkat_reversed (fd, file, contents);
76 }
77
78 #endif /* HAVE_SYMLINK */