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);
135 /* convert to absolute path */
136 if (NameFromLock(me
->pr_CurrentDir
, buf2
, sizeof(buf2
) - 1))
138 int namelen
= strlen(newName
);
140 if (len
+ namelen
< sizeof(buf2
) - 1)
142 if (buf2
[len
- 1] != ':')
144 CopyMem(newName
, buf2
+ len
, namelen
+ 1);
150 D(bug("[Dos] rename %s %s\n", oldName
, newName
));
152 /* get device pointers */
153 if ((olddvp
= GetDeviceProc(oldName
, NULL
)) == NULL
||
154 (newdvp
= GetDeviceProc(newName
, NULL
)) == NULL
) {
155 FreeDeviceProc(olddvp
);
159 /* make sure they're on the same device
160 * XXX this is insufficient, see comments in samedevice.c */
161 if (olddvp
->dvp_Port
!= newdvp
->dvp_Port
) {
162 FreeDeviceProc(olddvp
);
163 FreeDeviceProc(newdvp
);
164 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
168 iofs
.io_Union
.io_RENAME
.io_NewName
= StripVolume(newName
);
169 err
= DoIOFS(&iofs
, olddvp
, oldName
, DOSBase
);
171 FreeDeviceProc(olddvp
);
172 FreeDeviceProc(newdvp
);
174 return err
== 0 ? DOSTRUE
: DOSFALSE
;