Import upstream version 1.29
[debian/tar] / gnu / symlinkat.c
index e63bf472eb7875f52e7d922fa9a2895ee9e7f620..84d55847696fe59dcb59a13b9dd7c7ac4e407775 100644 (file)
@@ -1,7 +1,5 @@
-/* -*- buffer-read-only: t -*- vi: set ro: */
-/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
 /* Create a symlink relative to an open directory.
-   Copyright (C) 2009-2014 Free Software Foundation, Inc.
+   Copyright (C) 2009-2015 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <config.h>
 
 #include <unistd.h>
+#include <errno.h>
 
-#if !HAVE_SYMLINK
+#if HAVE_SYMLINKAT
+# undef symlinkat
+
+#include <sys/stat.h>
+#include <string.h>
+
+/* Create a symlink, but reject trailing slash.  */
+int
+rpl_symlinkat (char const *contents, int fd, char const *name)
+{
+  size_t len = strlen (name);
+  if (len && name[len - 1] == '/')
+    {
+      struct stat st;
+      if (fstatat (fd, name, &st, 0) == 0)
+        errno = EEXIST;
+      return -1;
+    }
+  return symlinkat (contents, fd, name);
+}
+
+#elif !HAVE_SYMLINK
 /* Mingw lacks symlink, and it is more efficient to provide a trivial
    wrapper than to go through at-func.c to call rpl_symlink.  */
 
-# include <errno.h>
-
 int
 symlinkat (char const *path1 _GL_UNUSED, int fd _GL_UNUSED,
            char const *path2 _GL_UNUSED)