From dadab98225fd15d513f11471ce65c2679fa5ea50 Mon Sep 17 00:00:00 2001 From: Brandon Turner Date: Fri, 16 Sep 2005 15:00:22 +0000 Subject: [PATCH] fix a bug in 'if exsist', it was only reading to the first space for the file name, ignoring quotes and there fore searching for bad file names. svn path=/trunk/; revision=17880 --- reactos/subsys/system/cmd/if.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/reactos/subsys/system/cmd/if.c b/reactos/subsys/system/cmd/if.c index 09e241c43b2..b630efb057c 100644 --- a/reactos/subsys/system/cmd/if.c +++ b/reactos/subsys/system/cmd/if.c @@ -69,15 +69,36 @@ INT cmd_if (LPTSTR cmd, LPTSTR param) param++; pp = param; - while (*pp && !_istspace (*pp)) + + INT i; + BOOL bInside = FALSE; + /* find the whole path to the file */ + for(i = 0; i < _tcslen(param); i++) + { + if(param[i] == _T('\"')) + bInside = !bInside; + if((param[i] == _T(' ')) && !bInside) + { + break; + } pp++; + } + *pp++ = _T('\0'); + i = 0; + /* remove quotes */ + while(i < _tcslen(param)) + { + if(param[i] == _T('\"')) + memmove(¶m[i],¶m[i + 1], _tcslen(¶m[i]) * sizeof(TCHAR)); + else + i++; + } if (*pp) - { + { WIN32_FIND_DATA f; HANDLE hFind; - - *pp++ = _T('\0'); + hFind = FindFirstFile (param, &f); x_flag ^= (hFind == INVALID_HANDLE_VALUE) ? 0 : X_EXEC; if (hFind != INVALID_HANDLE_VALUE)