2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
8 /*****************************************************************************
24 Without argument it shows the name of the current directory.
25 With argument it changes the current directory.
29 DIR -- path to change to current directory
43 ******************************************************************************/
45 #include <exec/execbase.h>
46 #include <exec/memory.h>
47 #include <proto/exec.h>
49 #include <proto/dos.h>
51 #include <aros/shcommands.h>
53 static STRPTR
GetLockName(BPTR lock
, struct ExecBase
*SysBase
,
54 struct DosLibrary
*DOSBase
);
57 AROS_SHA(STRPTR
, , DIR, , NULL
))
63 struct FileInfoBlock
*fib
;
64 LONG return_code
= 0, error
= 0;
68 dir
= Lock(SHArg(DIR), SHARED_LOCK
);
72 fib
= AllocDosObject(DOS_FIB
, NULL
);
76 if (Examine(dir
, fib
))
78 if (fib
->fib_DirEntryType
> 0)
81 dir
= CurrentDir(newdir
);
83 buf
= GetLockName(newdir
, SysBase
, DOSBase
);
86 SetCurrentDirName(buf
);
91 error
= ERROR_OBJECT_WRONG_TYPE
;
96 FreeDosObject(DOS_FIB
, fib
);
108 dir
= CurrentDir(BNULL
);
110 buf
= GetLockName(dir
, SysBase
, DOSBase
);
113 if (FPuts(Output(), buf
) < 0 || FPuts(Output(), "\n") < 0)
124 PrintFault(error
, "CD");
125 return_code
= RETURN_ERROR
;
134 static STRPTR
GetLockName(BPTR lock
, struct ExecBase
*SysBase
, struct DosLibrary
*DOSBase
)
140 for(i
= 256; buf
== NULL
&& error
== 0; i
+= 256)
142 buf
= AllocVec(i
, MEMF_PUBLIC
);
145 if (!NameFromLock(lock
, buf
, i
))
148 if (error
== ERROR_LINE_TOO_LONG
)