Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: never write "firstly" or "secondly"

...

In situations where the source file is supposed not to be a directory or symbolic link, an alternative solution is to use link() to link the source file to the destination file and then use unlink() (or remove()) to delete the source file. Since link() fails if the destination file exists, this avoids the need for calling access(). However, this solution has two race conditions related to the source file. FirstlyFirst, before calling link() the program must use lstat() to check that the source file is not a directory or symbolic link. SecondlySecond, there is the time window between the link() and the unlink() during which the source file could change. Consequently, this alternative solution can be safely executed only when the source file is located within a secure directory.

...