symlink.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Stub for symlink().
  2. Copyright (C) 2009-2011 Free Software Foundation, Inc.
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  13. #include <config.h>
  14. /* Specification. */
  15. #include <unistd.h>
  16. #include <errno.h>
  17. #include <string.h>
  18. #include <sys/stat.h>
  19. #if HAVE_SYMLINK
  20. # undef symlink
  21. /* Create a symlink, but reject trailing slash. */
  22. int
  23. rpl_symlink (char const *contents, char const *name)
  24. {
  25. size_t len = strlen (name);
  26. if (len && name[len - 1] == '/')
  27. {
  28. struct stat st;
  29. if (lstat (name, &st) == 0)
  30. errno = EEXIST;
  31. return -1;
  32. }
  33. return symlink (contents, name);
  34. }
  35. #else /* !HAVE_SYMLINK */
  36. /* The system does not support symlinks. */
  37. int
  38. symlink (char const *contents _GL_UNUSED,
  39. char const *name _GL_UNUSED)
  40. {
  41. errno = ENOSYS;
  42. return -1;
  43. }
  44. #endif /* !HAVE_SYMLINK */