- register char *p;
-
- strcpy (lockfile, XSTRING_DATA(fn));
-
- /* Shift the nondirectory part of the file name (including the null)
- right two characters. Here is one of the places where we'd have to
- do something to support 14-character-max file names. */
- for (p = lockfile + strlen (lockfile); p != lockfile && *p != '/'; p--)
- p[2] = *p;
-
- /* Insert the `.#'. */
- p[1] = '.';
- p[2] = '#';
+ Bufbyte *file_name = XSTRING_DATA (fn);
+ Bufbyte *p;
+ size_t dirlen;
+
+ for (p = file_name + XSTRING_LENGTH (fn) - 1;
+ p > file_name && !IS_ANY_SEP (p[-1]);
+ p--)
+ ;
+ dirlen = p - file_name;
+
+ memcpy (lockfile, file_name, dirlen);
+ p = lockfile + dirlen;
+ *(p++) = '.';
+ *(p++) = '#';
+ memcpy (p, file_name + dirlen, XSTRING_LENGTH (fn) - dirlen + 1);