-/* If MVDIR is defined, it should be the full filename of a setuid root
- program able to link and unlink directories. If MVDIR is not defined,
- then the capability of renaming directories may be missing. */
-
- if (S_ISDIR (from_stats.st_mode))
- {
- /* Need a setuid root process to link and unlink directories. */
- int status;
- pid_t pid = fork ();
- switch (pid)
- {
- case -1: /* Error. */
- return -1; /* errno already set */
-
- case 0: /* Child. */
- execl (MVDIR, "mvdir", from, to, (char *) 0);
- _exit (1);
-
- default: /* Parent. */
- while (wait (&status) != pid)
- /* Do nothing. */ ;
-
- if (status)
- {
- /* MVDIR failed. */
- errno = EIO;
- return -1;
- }
- }
- }
- else
-
-#endif /* MVDIR */
-
- {
- if (link (from, to))
- return -1;
- if (unlink (from) && errno != ENOENT)
- {
- unlink (to);
- return -1;
- }
- }
- return 0;