From 98ea056d588fc2041d1816e67d18d2dd9364da1a Mon Sep 17 00:00:00 2001 From: John Hodge Date: Mon, 22 Jul 2013 20:15:14 +0800 Subject: [PATCH] Usermode/CLIShell - Updated 'dir' command to use OpenChild --- Usermode/Applications/CLIShell_src/main.c | 30 +++++++---------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index ca06a058..501359a8 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -300,27 +300,23 @@ void Command_Cd(int argc, char **argv) */ void Command_Dir(int argc, char **argv) { - int dp, fp, dirLen; + int dp, fp; char modeStr[11] = "RWXrwxRWX "; - char tmpPath[1024]; - char *fileName; + char fileName[256]; t_sysFInfo info; t_sysACL acl; + + // -- Generate and open directory -- // Generate Directory Path + char tmpPath[1024]; if(argc > 1) - dirLen = GeneratePath(argv[1], gsCurrentDirectory, tmpPath); + GeneratePath(argv[1], gsCurrentDirectory, tmpPath); else - { strcpy(tmpPath, gsCurrentDirectory); - } - dirLen = strlen(tmpPath); - // Open Directory dp = _SysOpen(tmpPath, OPENFLAG_READ); - // Check if file opened - if(dp == -1) - { + if(dp == -1) { printf("Unable to open directory `%s', File cannot be found\n", tmpPath); return; } @@ -339,15 +335,7 @@ void Command_Dir(int argc, char **argv) return; } - // Append Shash for file paths - if(tmpPath[dirLen-1] != '/') - { - tmpPath[dirLen++] = '/'; - tmpPath[dirLen] = '\0'; - } - - fileName = (char*)(tmpPath+dirLen); - // Read Directory Content + // -- Read Directory Contents -- while( (fp = _SysReadDir(dp, fileName)) ) { if(fp < 0) @@ -357,7 +345,7 @@ void Command_Dir(int argc, char **argv) break; } // Open File - fp = _SysOpen(tmpPath, 0); + fp = _SysOpenChild(dp, fileName, 0); if(fp == -1) continue; // Get File Stats _SysFInfo(fp, &info, 0); -- 2.20.1