Do not try to get stack pointer from invalid ESP field, which coincidentally
[AROS.git] / rom / dos / getcurrentdirname.c
blob895c00419265e2fb073cd1f25efdabbea4101304
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Get the name of the current directory.
6 Lang: english
7 */
8 #include <proto/exec.h>
9 #include <dos/dos.h>
10 #include "dos_intern.h"
11 #include <string.h>
13 /*****************************************************************************
15 NAME */
16 #include <proto/dos.h>
18 AROS_LH2(BOOL, GetCurrentDirName,
20 /* SYNOPSIS */
21 AROS_LHA(STRPTR, buf, D1),
22 AROS_LHA(LONG , len, D2),
24 /* LOCATION */
25 struct DosLibrary *, DOSBase, 94, Dos)
27 /* FUNCTION
28 Copies the name of the current directory from the CLI structure
29 into the buffer. If the buffer is too small the name is truncated,
30 and a failure is returned. If the current process doesn't have
31 a CLI structure, a 0 length string is put into the buffer and a
32 failure is returned.
34 INPUTS
35 buf - Buffer for the name.
36 len - Size of the buffer in bytes.
38 RESULT
39 !=0 on success, 0 on failure. IoErr() gives additional information
40 in that case.
42 NOTES
43 Documented as returning ERROR_OBJECT_WRONG_TYPE if CLI structure
44 is not present but actually it fallbacks to NameFromLock().
46 EXAMPLE
48 BUGS
50 SEE ALSO
51 SetCurrentDirName()
53 INTERNALS
55 *****************************************************************************/
57 AROS_LIBFUNC_INIT
59 struct Process *me = (struct Process *)FindTask(NULL);
60 struct CommandLineInterface *cli = BADDR(me->pr_CLI);
61 STRPTR cname;
62 ULONG clen;
63 BOOL ret = DOSTRUE;
65 if (cli == NULL)
66 return NameFromLock(me->pr_CurrentDir, buf, len);
68 cname = AROS_BSTR_ADDR(cli->cli_SetName);
69 clen = (ULONG)AROS_BSTR_strlen(cli->cli_SetName);
70 if (clen >= (len-1))
72 clen = len-1;
73 me->pr_Result2 = ERROR_LINE_TOO_LONG;
74 ret = DOSFALSE;
76 CopyMem(cname, buf, clen);
77 buf[clen] = '\0';
79 return ret;
80 AROS_LIBFUNC_EXIT
81 } /* GetCurrentDirName */