added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / rom / dos / rename.c
blob9e57707802b5a3ea3c2b88cc2ebacca2c2d6b91d
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Rename a file
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include "dos_intern.h"
10 #include <string.h>
12 /*****************************************************************************
14 NAME */
15 #include <exec/types.h>
16 #include <proto/dos.h>
18 AROS_LH2(LONG, Rename,
20 /* SYNOPSIS */
21 AROS_LHA(CONST_STRPTR, oldName, D1),
22 AROS_LHA(CONST_STRPTR, newName, D2),
24 /* LOCATION */
25 struct DosLibrary *, DOSBase, 13, Dos)
27 /* FUNCTION
28 Renames a given file. The old name and the new name must point to the
29 same volume.
31 INPUTS
32 oldName - Name of the file to rename
33 newName - New name of the file to rename
35 RESULT
36 boolean - DOSTRUE or DOSFALSE. IoErr() provides additional information
37 on DOSFALSE.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
47 INTERNALS
48 Calls the action FSA_RENAME on the filesystem-handler.
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
53 struct DevProc *olddvp, *newdvp;
54 struct IOFileSys iofs;
55 LONG err;
56 struct Process *me = (struct Process *)FindTask(NULL);
57 char buf1[256], vol[32];
58 char buf2[256];
59 int len;
61 InitIOFS(&iofs, FSA_RENAME, DOSBase);
63 len = SplitName(oldName, ':', vol, 0, sizeof(vol) - 1);
65 if (len > 0)
67 /* get real name */
68 BPTR lock = Lock(oldName, SHARED_LOCK);
69 if (lock)
71 if (NameFromLock(lock, buf1, sizeof(buf1) -1 ))
72 oldName = buf1;
73 UnLock(lock);
76 else
78 /* convert to absolute path */
79 if (NameFromLock(me->pr_CurrentDir, buf1, sizeof(buf1) - 1))
81 int namelen = strlen(oldName);
82 len = strlen(buf1);
83 if (len + namelen < sizeof(buf1))
85 buf1[len++] = '/';
86 CopyMem(oldName, buf1 + len, namelen);
87 len += namelen;
88 buf1[len] = '\0';
89 oldName = buf1;
94 len = SplitName(newName, ':', vol, 0, sizeof(vol) - 1);
96 if (len <= 0)
98 /* convert to absolute path */
99 if (NameFromLock(me->pr_CurrentDir, buf2, sizeof(buf2) - 1))
101 int namelen = strlen(newName);
102 len = strlen(buf2);
103 if (len + namelen < sizeof(buf2))
105 buf2[len++] = '/';
106 CopyMem(newName, buf2 + len, namelen);
107 len += namelen;
108 buf2[len] = '\0';
109 newName = buf2;
114 /* get device pointers */
115 if ((olddvp = GetDeviceProc(oldName, NULL)) == NULL ||
116 (newdvp = GetDeviceProc(newName, NULL)) == NULL) {
117 FreeDeviceProc(olddvp);
118 return DOSFALSE;
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);
127 return DOSFALSE;
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;
138 AROS_LIBFUNC_EXIT
139 } /* Rename */