COHERENT manpages
This page displays the COHERENT manpage for rename() [Rename a file].
List of available manpages
Index
rename() -- System Call (libc) Rename a file #include <stdio.h> int rename(old; new) char *old, *new; The COHERENT system call rename() changes the name of a file, from the name pointed to by old to that pointed to by new. Both old and new must point to a valid file name. If new names a file that already exists, the old file is replaced by the file being renamed. rename() returns zero if it could rename old, and nonzero if it could not. If rename() could not rename old, its name remains unchanged. Example This example renames the file named in the first command-line argument to the name given in the second argument. #include <stdio.h> #include <stdlib.h> main(argc, argv) int argc; char *argv[]; { if (argc != 3) { fprintf(stderr, "usage: rename from to\n"); exit(EXIT_FAILURE); } if(rename(argv[1], argv[2])) { perror("rename failed"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); } See Also libc, link(), stdio.h, unlink() ANSI Standard, §7.9.4.2 POSIX Standard, §5.5.3 Notes The ANSI Standard states that rename() fails if old is open, or if its contents must be copied in order to rename it. Under COHERENT, it also fails if new is already open.