diff --git a/ChangeLog b/ChangeLog
index 0d32c040b8d60424f29a40220a18ab1d251bbff1..db8ae682be894b7783efd79a0ec906a5faaac916 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,6 @@
 2016-01-15  Benno Schulenberg  <bensberg@justemail.net>
 	* src/winio.c (set_modified): Plug another memory leak.
+	* src/files.c (set_modified): Move this function to its habitat.
 	* src/files.c (open_file): Return the fantastic file descriptor
 	when opening a non-existent file for reading succeeds.
 
diff --git a/src/files.c b/src/files.c
index 1b89c0e998ef9e73ee41e5eb5dac5fa370bb4f43..b324f6aedb467ae71a9f5708bc3b953a9ffef460 100644
--- a/src/files.c
+++ b/src/files.c
@@ -101,6 +101,32 @@ void initialize_buffer_text(void)
     openfile->totsize = 0;
 }
 
+/* Mark the current file as modified if it isn't already, and then
+ * update the titlebar to display the file's new status. */
+void set_modified(void)
+{
+    if (openfile->modified)
+	return;
+
+    openfile->modified = TRUE;
+    titlebar(NULL);
+
+#ifndef NANO_TINY
+    if (!ISSET(LOCKING) || openfile->filename[0] == '\0')
+	return;
+
+    if (openfile->lock_filename == NULL) {
+	/* TRANSLATORS: Try to keep this at most 76 characters. */
+	statusbar(_("Warning: Modifying a file which is not locked,"
+			" check directory permission?"));
+    } else {
+	char *fullname = get_full_path(openfile->filename);
+	write_lockfile(openfile->lock_filename, fullname, TRUE);
+	free(fullname);
+    }
+#endif
+}
+
 #ifndef NANO_TINY
 /* Actually write the lockfile.  This function will ALWAYS annihilate
  * any previous version of the file.  We'll borrow INSECURE_BACKUP here
diff --git a/src/winio.c b/src/winio.c
index 8f1c79a6da928171764f6d052dc83392a36b7dee..385b35881c3caf171eb012d22ead4e68bbd4cf78 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2093,30 +2093,6 @@ void titlebar(const char *path)
     wnoutrefresh(edit);
 }
 
-/* Mark the current file as modified if it isn't already, and then
- * update the titlebar to display the file's new status. */
-void set_modified(void)
-{
-    if (!openfile->modified) {
-	openfile->modified = TRUE;
-	titlebar(NULL);
-#ifndef NANO_TINY
-	if (ISSET(LOCKING)) {
-	    if (openfile->filename[0] == '\0')
-		return;
-	    else if (openfile->lock_filename == NULL) {
-		/* TRANSLATORS: Try to keep this at most 76 characters. */
-		statusbar(_("Warning: Modifying a file which is not locked, check directory permission?"));
-	    } else {
-		char *fullname = get_full_path(openfile->filename);
-		write_lockfile(openfile->lock_filename, fullname, TRUE);
-		free(fullname);
-	    }
-	}
-#endif
-    }
-}
-
 /* Display a message on the statusbar, and set disable_cursorpos to
  * TRUE, so that the message won't be immediately overwritten if
  * constant cursor position display is on. */