2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <proto/exec.h>
9 #include "dos_intern.h"
12 /*****************************************************************************
15 #include <exec/types.h>
16 #include <proto/dos.h>
18 AROS_LH2(LONG
, Rename
,
21 AROS_LHA(CONST_STRPTR
, oldName
, D1
),
22 AROS_LHA(CONST_STRPTR
, newName
, D2
),
25 struct DosLibrary
*, DOSBase
, 13, Dos
)
28 Renames a given file. The old name and the new name must point to the
32 oldName - Name of the file to rename
33 newName - New name of the file to rename
36 boolean - DOSTRUE or DOSFALSE. IoErr() provides additional information
48 Calls the action FSA_RENAME on the filesystem-handler.
50 *****************************************************************************/
53 struct DevProc
*olddvp
, *newdvp
;
54 struct IOFileSys iofs
;
56 struct Process
*me
= (struct Process
*)FindTask(NULL
);
57 char buf1
[256], vol
[32];
61 InitIOFS(&iofs
, FSA_RENAME
, DOSBase
);
63 len
= SplitName(oldName
, ':', vol
, 0, sizeof(vol
) - 1);
68 BPTR lock
= Lock(oldName
, SHARED_LOCK
);
71 if (NameFromLock(lock
, buf1
, sizeof(buf1
) -1 ))
78 /* convert to absolute path */
79 if (NameFromLock(me
->pr_CurrentDir
, buf1
, sizeof(buf1
) - 1))
81 int namelen
= strlen(oldName
);
83 if (len
+ namelen
< sizeof(buf1
))
86 CopyMem(oldName
, buf1
+ len
, namelen
);
94 len
= SplitName(newName
, ':', vol
, 0, sizeof(vol
) - 1);
98 /* convert to absolute path */
99 if (NameFromLock(me
->pr_CurrentDir
, buf2
, sizeof(buf2
) - 1))
101 int namelen
= strlen(newName
);
103 if (len
+ namelen
< sizeof(buf2
))
106 CopyMem(newName
, buf2
+ len
, namelen
);
114 /* get device pointers */
115 if ((olddvp
= GetDeviceProc(oldName
, NULL
)) == NULL
||
116 (newdvp
= GetDeviceProc(newName
, NULL
)) == NULL
) {
117 FreeDeviceProc(olddvp
);
121 /* make sure they're on the same device
122 * XXX this is insufficient, see comments in samedevice.c */
123 if (olddvp
->dvp_Port
!= newdvp
->dvp_Port
) {
124 FreeDeviceProc(olddvp
);
125 FreeDeviceProc(newdvp
);
126 SetIoErr(ERROR_RENAME_ACROSS_DEVICES
);
130 iofs
.io_Union
.io_RENAME
.io_NewName
= StripVolume(newName
);
131 err
= DoIOFS(&iofs
, olddvp
, oldName
, DOSBase
);
133 FreeDeviceProc(olddvp
);
134 FreeDeviceProc(newdvp
);
136 return err
== 0 ? DOSTRUE
: DOSFALSE
;