add ext4,vfat and tar.bz2
[u-tools.git] / u-tools / apps / tar / gnu / symlinkat.c
bloba4301de171452a12c0615210e6eb04c9e1e1b76e
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-2011 Free Software Foundation, Inc.
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.
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.
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/>. */
19 /* written by Eric Blake */
21 #include <config.h>
23 #include <unistd.h>
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. */
29 # include <errno.h>
31 int
32 symlinkat (char const *path1 _GL_UNUSED, int fd _GL_UNUSED,
33 char const *path2 _GL_UNUSED)
35 errno = ENOSYS;
36 return -1;
39 #else /* HAVE_SYMLINK */
41 /* Our openat helper functions expect the directory parameter first,
42 not second. These shims make life easier. */
44 /* Like symlink, but with arguments reversed. */
45 static int
46 symlink_reversed (char const *file, char const *contents)
48 return symlink (contents, file);
51 /* Like symlinkat, but with arguments reversed. */
53 static int
54 symlinkat_reversed (int fd, char const *file, char const *contents);
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
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. */
72 int
73 symlinkat (char const *contents, int fd, char const *file)
75 return symlinkat_reversed (fd, file, contents);
78 #endif /* HAVE_SYMLINK */