From 9b58425afdb5d4692fbf7750908c6d42572c687f Mon Sep 17 00:00:00 2001 From: neil Date: Fri, 10 Aug 2012 00:11:34 +0000 Subject: [PATCH] - Fixed mix-up of return codes and error codes, and calling of SetIoErr() before end of command. - Removed code duplication. git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@45421 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- workbench/c/shellcommands/CD.c | 142 ++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 80 deletions(-) diff --git a/workbench/c/shellcommands/CD.c b/workbench/c/shellcommands/CD.c index 7d1104a81d..e8f5fec96b 100644 --- a/workbench/c/shellcommands/CD.c +++ b/workbench/c/shellcommands/CD.c @@ -1,5 +1,5 @@ /* - Copyright © 1995-2001, The AROS Development Team. All rights reserved. + Copyright © 1995-2012, The AROS Development Team. All rights reserved. $Id$ Desc: CD CLI command @@ -50,17 +50,18 @@ #include -AROS_SH1(CD, 41.1, -AROS_SHA(STRPTR, ,DIR, ,NULL)) +static STRPTR GetLockName(BPTR lock, struct ExecBase *SysBase, + struct DosLibrary *DOSBase); + +AROS_SH1(CD, 41.2, + AROS_SHA(STRPTR, , DIR, , NULL)) { AROS_SHCOMMAND_INIT BPTR dir,newdir; STRPTR buf; - ULONG i; struct FileInfoBlock *fib; - LONG error = 0; - + LONG return_code = 0, error = 0; if (SHArg(DIR)) { @@ -79,103 +80,84 @@ AROS_SHA(STRPTR, ,DIR, ,NULL)) newdir = dir; dir = CurrentDir(newdir); - for (i = 256;;i += 256) - { - buf = AllocVec(i, MEMF_ANY); - - if (buf == NULL) - { - SetIoErr(ERROR_NO_FREE_STORE); - error = RETURN_ERROR; - break; - } - - if (NameFromLock(newdir, buf, i)) - { - SetCurrentDirName(buf); - FreeVec(buf); - break; - } - + buf = GetLockName(newdir, SysBase, DOSBase); + if (buf != NULL) + { + SetCurrentDirName(buf); FreeVec(buf); - - if (IoErr() != ERROR_LINE_TOO_LONG) - { - error = RETURN_ERROR; - break; - } - } + } } else - { - SetIoErr(ERROR_OBJECT_WRONG_TYPE); - error = RETURN_ERROR; - } + error = ERROR_OBJECT_WRONG_TYPE; } else - { - error = RETURN_ERROR; - } + error = IoErr(); FreeDosObject(DOS_FIB, fib); } else - { - SetIoErr(ERROR_NO_FREE_STORE); - error = RETURN_ERROR; - } + error = IoErr(); UnLock(dir); } else - { - error = RETURN_ERROR; - } + error = IoErr(); } else { dir = CurrentDir(BNULL); - for(i = 256;;i += 256) - { - buf = AllocVec(i, MEMF_ANY); - - if (buf == NULL) - { - SetIoErr(ERROR_NO_FREE_STORE); - error = RETURN_ERROR; - break; - } - - if (NameFromLock(dir, buf, i)) - { - if (FPuts(Output(), buf) < 0 || FPuts(Output(), "\n") < 0) - { - error = RETURN_ERROR; - } - - FreeVec(buf); - break; - } - - FreeVec(buf); - - if (IoErr() != ERROR_LINE_TOO_LONG) - { - error = RETURN_ERROR; - break; - } - } - + buf = GetLockName(dir, SysBase, DOSBase); + if (buf != NULL) + { + if (FPuts(Output(), buf) < 0 || FPuts(Output(), "\n") < 0) + error = IoErr(); + } + else + error = IoErr(); + FreeVec(buf); CurrentDir(dir); } - - if (error) + + if (error != 0) { - PrintFault(IoErr(), "CD"); + PrintFault(error, "CD"); + return_code = RETURN_ERROR; } - return error; + return return_code; AROS_SHCOMMAND_EXIT } + + +static STRPTR GetLockName(BPTR lock, struct ExecBase *SysBase, struct DosLibrary *DOSBase) +{ + LONG error = 0; + STRPTR buf = NULL; + ULONG i; + + for(i = 256; buf == NULL && error == 0; i += 256) + { + buf = AllocVec(i, MEMF_PUBLIC); + if (buf != NULL) + { + if (!NameFromLock(lock, buf, i)) + { + error = IoErr(); + if (error == ERROR_LINE_TOO_LONG) + { + error = 0; + FreeVec(buf); + buf = NULL; + } + } + } + else + error = IoErr(); + } + + if (error != 0) + SetIoErr(error); + return buf; +} -- 2.11.4.GIT