Support rastport clipping rectangle for layerless rastports
[tangerine.git] / rom / dos / namefromlock.c
blob5fa9a6809baebb0c9999b78497f3490a1734ea22
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Retrieve thew full pathname from a lock.
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <dos/exall.h>
10 #include <dos/filesystem.h>
11 #include "dos_intern.h"
12 #include <aros/debug.h>
14 struct MyExAllData
16 struct ExAllData ead;
17 UBYTE filenamebuffer[MAXFILENAMELENGTH + 1];
20 /*****************************************************************************
22 NAME */
23 #include <proto/dos.h>
25 AROS_LH3(BOOL, NameFromLock,
27 /* SYNOPSIS */
28 AROS_LHA(BPTR, lock, D1),
29 AROS_LHA(STRPTR, buffer, D2),
30 AROS_LHA(LONG, length, D3),
32 /* LOCATION */
33 struct DosLibrary *, DOSBase, 67, Dos)
35 /* FUNCTION
36 Get the full path name associated with a lock to a file or
37 directory into a user supplied buffer.
39 INPUTS
40 lock - Lock to file or directory.
41 buffer - Buffer to fill. Contains a NUL terminated string if
42 all went well.
43 length - Size of the buffer in bytes.
45 RESULT
46 !=0 if all went well, 0 in case of an error. IoErr() will
47 give additional information in that case.
49 *****************************************************************************/
51 /*****************************************************************************
53 NAME
54 #include <clib/dos_protos.h>
56 AROS_LH3(LONG, NameFromFH,
58 SYNOPSIS
59 AROS_LHA(BPTR , fh, D1),
60 AROS_LHA(STRPTR, buffer, D2),
61 AROS_LHA(LONG , len, D3),
63 LOCATION
64 struct DosLibrary *, DOSBase, 68, Dos)
66 FUNCTION
67 Get the full path name associated with file-handle into a
68 user supplied buffer.
70 INPUTS
71 fh - File-handle to file or directory.
72 buffer - Buffer to fill. Contains a NUL terminated string if
73 all went well.
74 length - Size of the buffer in bytes.
76 RESULT
77 !=0 if all went well, 0 in case of an error. IoErr() will
78 give additional information in that case.
80 *****************************************************************************/
81 /*AROS alias NameFromFH NameFromLock */
83 AROS_LIBFUNC_INIT
84 AROS_LIBBASE_EXT_DECL(struct DosLibrary *,DOSBase)
86 STRPTR s1, s2, name;
87 struct Unit *curlock, *oldlock=NULL;
88 struct MyExAllData stackead;
89 struct ExAllData *ead = &stackead.ead;
90 LONG error;
92 /* Get pointer to filehandle */
93 struct FileHandle *fh = (struct FileHandle *)BADDR(DupLock(lock));
95 /* Get pointer to process structure */
96 struct Process *me = (struct Process *)FindTask(NULL);
98 /* Get pointer to I/O request. Use stackspace for now. */
99 struct IOFileSys io, *iofs = &io;
101 if (fh == 0)
102 return DOSFALSE;
104 if (length < 1)
106 SetIoErr(ERROR_LINE_TOO_LONG);
108 return DOSFALSE;
111 /* Prepare I/O request. */
112 iofs->IOFS.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
113 iofs->IOFS.io_Message.mn_ReplyPort = &me->pr_MsgPort;
114 iofs->IOFS.io_Message.mn_Length = sizeof(struct IOFileSys);
116 iofs->IOFS.io_Device = (fh == NULL)
117 ? DOSBase->dl_NulHandler
118 : fh->fh_Device;
120 /* Construct the name from top to bottom */
121 name = buffer + length;
122 *--name = 0;
123 curlock = fh->fh_Unit;
125 /* Loop over path */
128 /* Read name of current lock (into the user supplied buffer) */
129 iofs->IOFS.io_Unit = curlock;
130 iofs->IOFS.io_Command = FSA_EXAMINE;
131 iofs->io_Union.io_EXAMINE.io_ead = ead;
132 iofs->io_Union.io_EXAMINE.io_Size = sizeof(stackead);
133 iofs->io_Union.io_EXAMINE.io_Mode = ED_TYPE;
135 DosDoIO(&iofs->IOFS);
137 error = iofs->io_DosError;
139 /* Move name to the top of the buffer. */
140 if(!error)
142 s1 = s2 = ead->ed_Name;
144 while(*s2++)
149 if(ead->ed_Type == ST_ROOT)
151 if (name > buffer)
153 *--name=':';
155 else
157 error = ERROR_LINE_TOO_LONG;
160 else if(oldlock != NULL)
162 if (name > buffer)
164 *--name = '/';
166 else
168 error = ERROR_LINE_TOO_LONG;
172 if (!error)
174 s2--;
176 if (name - (s2 - s1) >= buffer)
178 while(s2 > s1)
180 *--name = *--s2;
183 else
185 error = ERROR_LINE_TOO_LONG;
189 } /* if(!error) */
191 /* Read the parent's lock (if there is a parent) */
192 if(!error && (ead->ed_Type != ST_ROOT))
194 iofs->IOFS.io_Command = FSA_OPEN;
195 iofs->io_Union.io_OPEN.io_Filename = "/";
196 iofs->io_Union.io_OPEN.io_FileMode = 0;
198 DosDoIO(&iofs->IOFS);
200 curlock = iofs->IOFS.io_Unit;
201 error = iofs->io_DosError;
204 /* Free the old lock if it was allocated by NameFromLock(). */
205 if(oldlock != NULL)
207 iofs->IOFS.io_Unit = oldlock;
208 iofs->IOFS.io_Command = FSA_CLOSE;
210 DosDoIO(&iofs->IOFS);
213 oldlock = curlock;
216 while(!error && (ead->ed_Type != ST_ROOT));
218 /* Move the name from the top to the bottom of the buffer. */
220 if (!error)
222 UBYTE c, old_c = '\0';
226 c = *name++;
228 if ((c != '/') || (old_c != ':'))
230 *buffer++ = c;
233 old_c = c;
236 while (c);
239 UnLock((BPTR)MKBADDR(fh));
241 /* All done. */
243 SetIoErr(error);
245 return error
246 ? DOSFALSE
247 : DOSTRUE;
249 AROS_LIBFUNC_EXIT
251 } /* NameFromLock */