muimaster.library: introduce a hack to make sure up/down arrows always work
[AROS.git] / compiler / posixc / rename.c
blob711fb7b7524a088455130614be95613955fa35e1
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function rename() with optional Amiga<>Posix file name conversion.
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
47 Uses stdcio.library rename() function after path name conversion
49 ******************************************************************************/
50 int __posixc_rename (const char * oldpath, const char * newpath)
52 STRPTR aoldpath = (STRPTR)strdup((const char*)__path_u2a(oldpath));
53 CONST_STRPTR anewpath = __path_u2a(newpath);
54 int ret;
56 /* __path_u2a has resolved paths like /toto/../a */
57 if (anewpath[0] == '.')
59 if (anewpath[1] == '\0' || (anewpath[1] == '.' && anewpath[2] == '\0'))
61 errno = EEXIST;
62 free(aoldpath);
63 return -1;
67 ret = rename(aoldpath, anewpath);
69 free(aoldpath);
71 return ret;
72 } /* rename */