Node:Renaming files at a low level, Previous:Deleting files at a low level, Up:Low-level file routines
If you want to rename a file, you can use the rename
function,
which takes two parameters. The first parameter is a string containing
the old name of the file, and the second is a string containing the new
name. (As with unlink
, this function only operates on one of the
names of a file, if the file has hard links. See Deleting files at a low level, for caveats and information on hard links.)
Both the new name and the old name must be on the same file system. Any file in the same directory that has the same name as the new file name will be deleted in the process of renaming the file.
If rename
fails, it will return -1. In addition to the usual
file name errors, unlink
can set errno
to the following
values. (See Usual file name errors, for a list of the usual file
name errors.)
EACCES
EBUSY
ENOTEMPTY
EEXIST
, but GNU always returns ENOTEMPTY
.
EINVAL
EISDIR
EMLINK
ENOENT
ENOSPC
EROFS
EXDEV