r6831@lvps87-230-33-50: verhaegs | 2008-02-03 14:08:57 +0100
[tangerine.git] / compiler / clib / rename.c
blobb37bac65da4292364f08e0873591586d7265695b
1 /*
2 Copyright © 1995-2003, The AROS Development Team. All rights reserved.
3 $Id$
5 ANSI C function rename().
6 */
8 #include <proto/dos.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "__errno.h"
12 #include "__upath.h"
14 #define DEBUG 0
15 #include <aros/debug.h>
17 /*****************************************************************************
19 NAME */
20 #include <stdio.h>
22 int rename (
24 /* SYNOPSIS */
25 const char * oldpath,
26 const char * newpath)
28 /* FUNCTION
29 Renames a file or directory.
31 INPUTS
32 oldpath - Complete path to existing file or directory.
33 newpath - Complete path to the new file or directory.
35 RESULT
36 0 on success and -1 on error. In case of an error, errno is set.
38 NOTES
40 EXAMPLE
42 BUGS
44 SEE ALSO
46 INTERNALS
48 ******************************************************************************/
50 char *aoldpath = strdup(__path_u2a(oldpath));
51 const char *anewpath = __path_u2a(newpath);
53 if (!Rename (aoldpath, anewpath))
55 int ioerr = IoErr();
56 errno = IoErr2errno (ioerr);
57 D(bug("rename(%s, %s) errno=%d, IoErr=%d\n", aoldpath, anewpath,
58 errno, ioerr));
59 free(aoldpath);
60 return -1;
63 free(aoldpath);
64 return 0;
66 } /* rename */