rename

Function Prototype

int rename(const char *oldname, const char *newname);

Function

If oldname is a file:

  • If newname exists and not dir, then remove newname and rename oldname to newname
  • If newname exists and is dir, poses an error
  • must have write and execute permission for directories containing oldname and newname

If oldname is a directory:

  • If newname exists and is an empty directory, then remove newname and rename oldname to newname
  • If newname exists and is a file, then poses error
  • If oldname is prefix of newname, poses an error, e.g.,
    • oldname = "/usr/old_dir"
    • newname = "/usr/old_dir/new_dir"
  • must have write and execute permission for directories containing oldname and newname