Indentation fix, cleanup.
[AROS.git] / rom / dos / namefrom.c
blob8e1f3a092ef067f8940be886f597eb92fa796303
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Retrieve the full pathname from a lock or a filehandle.
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include "dos_intern.h"
11 #include <proto/dos.h>
12 #include <aros/debug.h>
14 BOOL namefrom_internal(struct DosLibrary *DOSBase, BPTR lock, STRPTR buffer, LONG length)
16 STRPTR s1, s2, name;
17 D(STRPTR origbuffer;)
18 BPTR parentlock, origlock;
19 struct FileInfoBlock *fib;
20 struct MsgPort *port;
21 LONG error;
22 SIPTR code = DOSFALSE;
23 BOOL first = TRUE;
25 D(origbuffer = buffer);
26 D(bug("[DOS] namefrom_internal(0x%p, 0x%p, %d)\n", BADDR(lock), buffer, length));
28 if (length < 1)
30 SetIoErr(ERROR_LINE_TOO_LONG);
31 return DOSFALSE;
34 fib = AllocDosObject(DOS_FIB, 0);
35 if (!fib)
37 SetIoErr(ERROR_NO_FREE_STORE);
38 return DOSFALSE;
41 if (lock != BNULL) {
42 port = ((struct FileLock*)BADDR(lock))->fl_Task;
43 } else {
44 port = DOSBase->dl_Root->rn_BootProc;
47 /* Construct the name from top to bottom */
48 name = buffer + length;
49 *--name = 0;
51 origlock = lock;
52 parentlock = BNULL;
54 /* Loop over path */
57 error = dopacket2(DOSBase, NULL, port, ACTION_EXAMINE_OBJECT, lock, MKBADDR(fib)) == 0;
58 //bug("name='%s'\n", fib->fib_FileName);
59 if (!error) {
60 parentlock = (BPTR)dopacket1(DOSBase, &code, port, ACTION_PARENT, lock);
61 if (!parentlock && !first)
62 error = code;
63 //bug("parentlock=%x\n", parentlock);
65 if (lock != origlock && lock)
66 UnLock(lock);
68 lock = parentlock;
70 /* Move name to the top of the buffer. */
71 if(!error)
73 fixfib(fib);
74 s1 = s2 = fib->fib_FileName;
76 while(*s2++)
81 if(!parentlock)
83 if (name > buffer)
85 *--name=':';
87 else
89 error = ERROR_LINE_TOO_LONG;
92 else if(!first)
94 if (name > buffer)
96 *--name = '/';
98 else
100 error = ERROR_LINE_TOO_LONG;
104 if (!error)
106 s2--;
108 if (name - (s2 - s1) >= buffer)
110 while(s2 > s1)
112 *--name = *--s2;
115 else
117 error = ERROR_LINE_TOO_LONG;
121 } /* if(!error) */
122 first = FALSE;
125 while(!error && parentlock);
127 /* Move the name from the top to the bottom of the buffer. */
128 if ((!error) && (name != buffer))
130 UBYTE c, old_c = '\0';
134 c = *name++;
136 if ((c != '/') || (old_c != ':'))
138 *buffer++ = c;
141 old_c = c;
144 while (c);
147 FreeDosObject(DOS_FIB, fib);
149 /* All done. */
151 SetIoErr(error);
153 D(bug("[NameFromX]='%s':%d\n", origbuffer, error));
155 return error
156 ? DOSFALSE
157 : DOSTRUE;