2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
11 #include <aros/debug.h>
13 /*****************************************************************************
25 Renames a file or directory.
28 oldpath - Complete path to existing file or directory.
29 newpath - Complete path to the new file or directory.
32 0 on success and -1 on error. In case of an error, errno is set.
44 ******************************************************************************/
46 BPTR oldlock
, newlock
;
48 /* try to delete newpath first */
51 newlock
= Lock(newpath
, SHARED_LOCK
);
56 oldlock
= Lock(oldpath
, EXCLUSIVE_LOCK
);
61 /* DeleteFile returns an error if directory is non-empty */
62 if (!DeleteFile(newpath
))
65 errno
= __stdc_ioerr2errno(ioerr
);
66 D(bug("rename(%s, %s) delete errno=%d, IoErr=%d\n",
67 oldpath
, newpath
, errno
, ioerr
));
74 if (!Rename (oldpath
, newpath
))
77 errno
= __stdc_ioerr2errno(ioerr
);
78 D(bug("rename(%s, %s) errno=%d, IoErr=%d\n",
79 oldpath
, newpath
, errno
, ioerr
));