I've been using GNU/Linux for over 10 years now, so I consider myself pretty familiar with file permissions.
To test the following code, I used 'chmod -w' on 'undo_path'. I then verified that the file had no write permissions by using ls -al. It showed:
-r--r--r-- 1 andy andy 52 Sep 26 18:17 lastrmw
if (remove (undo_path))
fprintf (stderr, "Warning: failed to remove %s\n", undo_path);
remove function is an operation on a directory that removes an entry from it. It does not delete a file unless it happens to produce the conditions under which a file is automatically deleted by the file system. If, for example, the same file has two corresponding directory entries or is opened by a process, it will not be deleted.