+
+#ifdef __APPLE__
+ if (argc == 2 && !lstat(argv[0], &fsb) && !lstat(argv[1], &tsb) &&
+ fsb.st_ino == tsb.st_ino && fsb.st_dev == tsb.st_dev &&
+ fsb.st_gen == tsb.st_gen) {
+ /*
+ * We appear to be trying to move a directory into itself,
+ * but it may be that the filesystem is case insensitive and
+ * we are trying to rename the directory to a case-variant.
+ * Ignoring trailing slashes, we look for any difference in
+ * the directory names. If there is a difference we do
+ * the rename, otherwise we fall-thru to the traditional
+ * error. Note the lstat calls above (rather than stat)
+ * permit the renaming of symlinks to case-variants.
+ */
+ char *q;
+
+ for (p = argv[0] + strlen(argv[0]); p != argv[0]; ) {
+ p--;
+ if (*p != '/')
+ break;
+ }
+ for (q = argv[1] + strlen(argv[1]); q != argv[1]; ) {
+ q--;
+ if (*q != '/')
+ break;
+ }
+ for ( ; ; p--, q--) {
+ if (*p != *q)
+ exit(do_move(argv[0], argv[1]));
+ if (*p == '/')
+ break;
+ if (p == argv[0]) {
+ if (q == argv[1] || *(q-1) == '/')
+ break;
+ exit(do_move(argv[0], argv[1]));
+ }
+ if (q == argv[1]) {
+ if (p == argv[0] || *(p-1) == '/')
+ break;
+ exit(do_move(argv[0], argv[1]));
+ }
+ }
+ }
+#endif /* __APPLE__ */