diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2015-07-04 17:13:50 +0300 |
commit | 71cd8e3a743046573744123777061b64881bf372 (patch) | |
tree | 82522befe647f4fff186a5630cad0cad33f8ef53 /gnulib-tests/symlinkat.c | |
parent | c18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff) | |
download | coreutils-upstream.tar.gz |
Imported Upstream version 8.24upstream/8.24upstream
Diffstat (limited to 'gnulib-tests/symlinkat.c')
-rw-r--r-- | gnulib-tests/symlinkat.c | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/gnulib-tests/symlinkat.c b/gnulib-tests/symlinkat.c index 26a88f9d..84d55847 100644 --- a/gnulib-tests/symlinkat.c +++ b/gnulib-tests/symlinkat.c @@ -1,5 +1,5 @@ /* 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 @@ -19,13 +19,33 @@ #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) |