#include <stdio.h>
|
int
rename (const char *from, const char *to); |
If the final component of from is a symbolic link, the symbolic link is renamed, not the file or directory to which it points.
If a file with a symbolic link pointing to it is renamed, then a subsequent open call on the symbolic link file would automatically remove the link file, i.e consider a symbolic file link.x pointing to a file abc.x. If the file abc.x is renamed to abcd.x then, a subsequent open call on link.x file would automatically remove link.x file.
Note: 1>rename call doesn’t differenciate between hard and soft links. 2>If the specified file is a dangling link file, then this link file will be automatically removed.
Limitation: rename call fails if from and to are files, and are in use(i.e., if any one of these files is kept open by a process). Parent directory time stamps remain uneffected if rename creates a new entry in the directory, this new entry has only two time stamps, modification and access time stamps, here access time stamp is equal to modification time stamp.
/**************************************************************************************** * Detailed description: This sample code demonstrates usage of rename system call. * * Preconditions: Example.cfg file should be present in the current working directory. ****************************************************************************************/ #include <stdio.h> int main() { if(rename("Example.txt" , "Example2.txt") < 0 ) { printf("Failed to rename Example.txt\n"); return -1; } printf("Rename successful \n"); return 0; }
Output
Rename successful
[ENAMETOOLONG] | |
A component or an entire path name exceeded 255 characters. | |
[ENOENT] | |
A component of the from path does not exist, or a path prefix of to does not exist. | |
[EACCES] | |
A component of either path prefix denies search permission(Not supported). | |
[EACCES] | |
The requested link requires writing in a directory with a mode
that denies write permission(Not supported).
|
|
[EPERM] | |
The directory containing
from
is marked sticky,
and neither the containing directory nor
from
are owned by the effective user ID.
Too many symbolic links were encountered in translating either pathname(Currenlty not supported). |
|
[ENOTDIR] | |
A component of either path prefix is not a directory. | |
[ENOTDIR] | |
The from argument is a directory, but to is not a directory. | |
[EISDIR] | |
The to argument is a directory, but from is not a directory. | |
[EXDEV] | |
The link named by to and the file named by from are on different logical devices (file systems). Note that this error code will not be returned if the implementation permits cross-device links(Not supported). | |
[ENOSPC] | |
The directory in which the entry for the new name is being placed cannot be extended because there is no space left on the file system containing the directory(Currently not supported). | |
[EDQUOT] | |
The directory in which the entry for the new name is being placed cannot be extended because the user’s quota of disk blocks on the file system containing the directory has been exhausted(Currently not supported). | |
[EIO] | An I/O error occurred while making or updating a directory entry(Not supported). |
[EROFS] | |
The requested link requires writing in a directory on a read-only file system(Not supported). | |
[EFAULT] | |
Path points outside the process’s allocated address space(Currently not supported). | |
[EINVAL] | |
The from argument is a parent directory of to, or an attempt is made to rename ‘.’ or ‘..’. | |
[ENOTEMPTY] | |
The to argument is a directory and is not empty. | |
The rename system call is expected to conform to -p1003.1-96.
© 2005-2007 Nokia |