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 *****************************************************************************/
56 struct DevProc
*olddvp
, *newdvp
;
58 struct Process
*me
= (struct Process
*)FindTask(NULL
);
59 char buf1
[256], vol
[32];
62 BSTR bstrNewName
, bstrOldName
;
64 ASSERT_VALID_PROCESS(me
);
66 len
= SplitName(oldName
, ':', vol
, 0, sizeof(vol
) - 1);
71 BPTR lock
= Lock(oldName
, SHARED_LOCK
);
74 if (NameFromLock(lock
, buf1
, sizeof(buf1
) - 1))
81 /* convert to absolute path */
82 if (NameFromLock(me
->pr_CurrentDir
, buf1
, sizeof(buf1
) - 1))
84 int namelen
= strlen(oldName
);
86 if (len
+ namelen
< sizeof(buf1
) - 1)
88 if (buf1
[len
- 1] != ':')
90 CopyMem(oldName
, buf1
+ len
, namelen
+ 1);
96 len
= SplitName(newName
, ':', vol
, 0, sizeof(vol
) - 1);
100 /* get real name of destination path */
105 strcpy(buf2
, newName
);
106 pos
= strrchr(buf2
, '/');
115 lock
= Lock(buf2
, SHARED_LOCK
);
118 if (NameFromLock(lock
, buf2
, sizeof(buf2
) - 1))
122 pos2
= newName
+ (int)(pos
- buf2
);
123 namelen
= strlen(pos2
);
124 if (len
+ namelen
< sizeof(buf2
) - 1)
126 if (buf2
[len
- 1] != ':')
128 CopyMem(pos2
, buf2
+ len
, namelen
+ 1);
137 /* convert to absolute path */
138 if (NameFromLock(me
->pr_CurrentDir
, buf2
, sizeof(buf2
) - 1))
140 int namelen
= strlen(newName
);
142 if (len
+ namelen
< sizeof(buf2
) - 1)
144 if (buf2
[len
- 1] != ':')
146 CopyMem(newName
, buf2
+ len
, namelen
+ 1);
152 D(bug("[Dos] rename %s %s\n", oldName
, newName
));
154 /* get device pointers */
155 if ((olddvp
= GetDeviceProc(oldName
, NULL
)) == NULL
||
156 (newdvp
= GetDeviceProc(newName
, NULL
)) == NULL
) {
157 FreeDeviceProc(olddvp
);
161 /* make sure they're on the same device
162 * XXX this is insufficient, see comments in samedevice.c */
163 if (olddvp
->dvp_Port
!= newdvp
->dvp_Port
) {
164 FreeDeviceProc(olddvp
);
165 FreeDeviceProc(newdvp
);
166 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
170 bstrNewName
= C2BSTR(newName
);
171 bstrOldName
= C2BSTR(oldName
);
172 status
= dopacket4(DOSBase
, NULL
, olddvp
->dvp_Port
, ACTION_RENAME_OBJECT
, olddvp
->dvp_Lock
, bstrOldName
, newdvp
->dvp_Lock
, bstrNewName
);
173 FREEC2BSTR(bstrOldName
);
174 FREEC2BSTR(bstrNewName
);
176 FreeDeviceProc(olddvp
);
177 FreeDeviceProc(newdvp
);