Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / dos / namefromlock.c
blob08ec70257596fd36e796f7a4008d8642ffa4ad9d
1 /*
2 Copyright © 1995-2007, 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
85 STRPTR s1, s2, name;
86 struct Unit *curlock, *oldlock=NULL;
87 struct MyExAllData stackead;
88 struct ExAllData *ead = &stackead.ead;
89 LONG error;
91 /* Get pointer to filehandle */
92 struct FileHandle *fh = (struct FileHandle *)BADDR(DupLock(lock));
94 /* Get pointer to process structure */
95 struct Process *me = (struct Process *)FindTask(NULL);
97 /* Get pointer to I/O request. Use stackspace for now. */
98 struct IOFileSys io, *iofs = &io;
100 if (fh == 0)
101 return DOSFALSE;
103 if (length < 1)
105 SetIoErr(ERROR_LINE_TOO_LONG);
107 return DOSFALSE;
110 /* Prepare I/O request. */
111 iofs->IOFS.io_Message.mn_Node.ln_Type = NT_REPLYMSG;
112 iofs->IOFS.io_Message.mn_ReplyPort = &me->pr_MsgPort;
113 iofs->IOFS.io_Message.mn_Length = sizeof(struct IOFileSys);
115 iofs->IOFS.io_Device = (fh == NULL)
116 ? DOSBase->dl_NulHandler
117 : fh->fh_Device;
119 /* Construct the name from top to bottom */
120 name = buffer + length;
121 *--name = 0;
122 curlock = fh->fh_Unit;
124 /* Loop over path */
127 /* Read name of current lock (into the user supplied buffer) */
128 iofs->IOFS.io_Unit = curlock;
129 iofs->IOFS.io_Command = FSA_EXAMINE;
130 iofs->io_Union.io_EXAMINE.io_ead = ead;
131 iofs->io_Union.io_EXAMINE.io_Size = sizeof(stackead);
132 iofs->io_Union.io_EXAMINE.io_Mode = ED_TYPE;
134 DosDoIO(&iofs->IOFS);
136 error = iofs->io_DosError;
138 /* Move name to the top of the buffer. */
139 if(!error)
141 s1 = s2 = ead->ed_Name;
143 while(*s2++)
148 if(ead->ed_Type == ST_ROOT)
150 if (name > buffer)
152 *--name=':';
154 else
156 error = ERROR_LINE_TOO_LONG;
159 else if(oldlock != NULL)
161 if (name > buffer)
163 *--name = '/';
165 else
167 error = ERROR_LINE_TOO_LONG;
171 if (!error)
173 s2--;
175 if (name - (s2 - s1) >= buffer)
177 while(s2 > s1)
179 *--name = *--s2;
182 else
184 error = ERROR_LINE_TOO_LONG;
188 } /* if(!error) */
190 /* Read the parent's lock (if there is a parent) */
191 if(!error && (ead->ed_Type != ST_ROOT))
193 iofs->IOFS.io_Command = FSA_OPEN;
194 iofs->io_Union.io_OPEN.io_Filename = "/";
195 iofs->io_Union.io_OPEN.io_FileMode = 0;
197 DosDoIO(&iofs->IOFS);
199 curlock = iofs->IOFS.io_Unit;
200 error = iofs->io_DosError;
203 /* Free the old lock if it was allocated by NameFromLock(). */
204 if(oldlock != NULL)
206 iofs->IOFS.io_Unit = oldlock;
207 iofs->IOFS.io_Command = FSA_CLOSE;
209 DosDoIO(&iofs->IOFS);
212 oldlock = curlock;
215 while(!error && (ead->ed_Type != ST_ROOT));
217 /* Move the name from the top to the bottom of the buffer. */
219 if (!error)
221 UBYTE c, old_c = '\0';
225 c = *name++;
227 if ((c != '/') || (old_c != ':'))
229 *buffer++ = c;
232 old_c = c;
235 while (c);
238 UnLock((BPTR)MKBADDR(fh));
240 /* All done. */
242 SetIoErr(error);
244 return error
245 ? DOSFALSE
246 : DOSTRUE;
248 AROS_LIBFUNC_EXIT
250 } /* NameFromLock */