This documentation is copyright © 1998-2001 Sandro Sigala <sandro@sigala.it>.
All rights reserved.

Released under the GNU General Public License.

Return to index Return to header Previous symbol Next symbol

rename

Prototype

#include <stdio.h>

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

Description

Renames the specified oldname file to the newname name. The behavior is implementation-defined if a file named newname already exists before the call of rename. Returns zero if the operation succeeds, nonzero if it fails.

Example

View source
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*
 * ren.c: rename the specified file.
 * usage: ren <oldname> <newname>
 */
int main(int argc, char **argv)
{
    if (argc != 3) {
	fprintf(stderr, "usage: %s <oldname> <newname>\n",
		argv[0]);
	return EXIT_FAILURE;
    }

    if (rename(argv[1], argv[2]) != 0) {
	fprintf(stderr, "%s:%s: %s\n", argv[0], argv[1],
		strerror(errno));
	return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

References

ISO C 9899:1990 7.9.4.2