+ if (link (old, new) == 0)
+ return unlink (old) == 0 || errno == ENOENT ? 0 : -1;
+ if (errno != ENOSYS && errno != LINKS_MIGHT_NOT_WORK)
+ return -1;
+
+ /* 'link' does not work on this file system. This can occur on
+ a GNU/Linux host mounting a FAT32 file system. Fall back on
+ 'rename' after checking that NEW does not exist. There is a
+ potential race condition since some other process may create
+ NEW immediately after the existence check, but it's the best
+ we can portably do here. */
+ if (lstat (new, &st) == 0 || errno == EOVERFLOW)
+ {
+ errno = EEXIST;
+ return -1;
+ }
+ if (errno != ENOENT)
+ return -1;
+ }
+
+ return rename (old, new);
+#endif
+}
+
+/* Create the lock file FILE with contents CONTENTS. Return 0 if
+ successful, an errno value on failure. If FORCE, remove any
+ existing FILE if necessary. */
+
+static int
+create_lock_file (char *lfname, char *lock_info_str, bool force)
+{
+#ifdef WINDOWSNT
+ /* Symlinks are supported only by later versions of Windows, and
+ creating them is a privileged operation that often triggers
+ User Account Control elevation prompts. Avoid the problem by
+ pretending that 'symlink' does not work. */
+ int err = ENOSYS;