2 Copyright © 1995-2008, The AROS Development Team. All rights reserved.
9 #include <aros/debug.h>
10 #include <proto/exec.h>
11 #include "dos_intern.h"
14 /*****************************************************************************
17 #include <exec/types.h>
18 #include <proto/dos.h>
20 AROS_LH2(LONG
, Rename
,
23 AROS_LHA(CONST_STRPTR
, oldName
, D1
),
24 AROS_LHA(CONST_STRPTR
, newName
, D2
),
27 struct DosLibrary
*, DOSBase
, 13, Dos
)
30 Renames a given file. The old name and the new name must point to the
34 oldName - Name of the file to rename
35 newName - New name of the file to rename
38 boolean - DOSTRUE or DOSFALSE. IoErr() provides additional information
50 Calls the action FSA_RENAME on the filesystem-handler.
52 *****************************************************************************/
55 struct DevProc
*olddvp
, *newdvp
;
56 struct IOFileSys iofs
;
58 struct Process
*me
= (struct Process
*)FindTask(NULL
);
59 char buf1
[256], vol
[32];
63 InitIOFS(&iofs
, FSA_RENAME
, DOSBase
);
65 len
= SplitName(oldName
, ':', vol
, 0, sizeof(vol
) - 1);
70 BPTR lock
= Lock(oldName
, SHARED_LOCK
);
73 if (NameFromLock(lock
, buf1
, sizeof(buf1
) - 1))
80 /* convert to absolute path */
81 if (NameFromLock(me
->pr_CurrentDir
, buf1
, sizeof(buf1
) - 1))
83 int namelen
= strlen(oldName
);
85 if (len
+ namelen
< sizeof(buf1
) - 1)
87 if (buf1
[len
- 1] != ':')
89 CopyMem(oldName
, buf1
+ len
, namelen
+ 1);
95 len
= SplitName(newName
, ':', vol
, 0, sizeof(vol
) - 1);
99 /* get real name of destination path */
104 strcpy(buf2
, newName
);
105 pos
= strrchr(buf2
, '/');
114 lock
= Lock(buf2
, SHARED_LOCK
);
117 if (NameFromLock(lock
, buf2
, sizeof(buf2
) - 1))
121 pos2
= newName
+ (int)(pos
- buf2
);
122 namelen
= strlen(pos2
);
123 if (len
+ namelen
< sizeof(buf2
) - 1)
125 if (buf2
[len
- 1] != ':')
127 CopyMem(pos2
, buf2
+ len
, namelen
+ 1);
136 /* convert to absolute path */
137 if (NameFromLock(me
->pr_CurrentDir
, buf2
, sizeof(buf2
) - 1))
139 int namelen
= strlen(newName
);
141 if (len
+ namelen
< sizeof(buf2
) - 1)
143 if (buf2
[len
- 1] != ':')
145 CopyMem(newName
, buf2
+ len
, namelen
+ 1);
151 D(bug("[Dos] rename %s %s\n", oldName
, newName
));
153 /* get device pointers */
154 if ((olddvp
= GetDeviceProc(oldName
, NULL
)) == NULL
||
155 (newdvp
= GetDeviceProc(newName
, NULL
)) == NULL
) {
156 FreeDeviceProc(olddvp
);
160 /* make sure they're on the same device
161 * XXX this is insufficient, see comments in samedevice.c */
162 if (olddvp
->dvp_Port
!= newdvp
->dvp_Port
) {
163 FreeDeviceProc(olddvp
);
164 FreeDeviceProc(newdvp
);
165 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
169 iofs
.io_Union
.io_RENAME
.io_NewName
= StripVolume(newName
);
170 err
= DoIOFS(&iofs
, olddvp
, oldName
, DOSBase
);
172 FreeDeviceProc(olddvp
);
173 FreeDeviceProc(newdvp
);
175 return err
== 0 ? DOSTRUE
: DOSFALSE
;