2 Copyright © 1995-2001, 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>
54 AROS_SHA(STRPTR
, ,DIR, ,NULL
))
61 struct FileInfoBlock
*fib
;
67 dir
= Lock(SHArg(DIR), SHARED_LOCK
);
71 fib
= AllocDosObject(DOS_FIB
, NULL
);
75 if (Examine(dir
, fib
))
77 if (fib
->fib_DirEntryType
> 0)
80 dir
= CurrentDir(newdir
);
82 for (i
= 256;;i
+= 256)
84 buf
= AllocVec(i
, MEMF_ANY
);
88 SetIoErr(ERROR_NO_FREE_STORE
);
93 if (NameFromLock(newdir
, buf
, i
))
95 SetCurrentDirName(buf
);
102 if (IoErr() != ERROR_LINE_TOO_LONG
)
104 error
= RETURN_ERROR
;
111 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
112 error
= RETURN_ERROR
;
117 error
= RETURN_ERROR
;
120 FreeDosObject(DOS_FIB
, fib
);
124 SetIoErr(ERROR_NO_FREE_STORE
);
125 error
= RETURN_ERROR
;
132 error
= RETURN_ERROR
;
137 dir
= CurrentDir(NULL
);
139 for(i
= 256;;i
+= 256)
141 buf
= AllocVec(i
, MEMF_ANY
);
145 SetIoErr(ERROR_NO_FREE_STORE
);
146 error
= RETURN_ERROR
;
150 if (NameFromLock(dir
, buf
, i
))
152 if (FPuts(Output(), buf
) < 0 || FPuts(Output(), "\n") < 0)
154 error
= RETURN_ERROR
;
163 if (IoErr() != ERROR_LINE_TOO_LONG
)
165 error
= RETURN_ERROR
;
175 PrintFault(IoErr(), "CD");