Index: /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp
===================================================================
--- /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp	(revision 71123)
+++ /trunk/src/VBox/Additions/common/VBoxService/VBoxServiceToolBox.cpp	(revision 71124)
@@ -889,8 +889,4 @@
     uint32_t fOutputFlags = VBOXSERVICETOOLBOXOUTPUTFLAG_NONE;
 
-    /* Init file list. */
-    RTLISTANCHOR fileList;
-    RTListInit(&fileList);
-
     while (   (ch = RTGetOpt(&GetState, &ValueUnion))
            && RT_SUCCESS(rc))
@@ -929,14 +925,6 @@
 
             case VINF_GETOPT_NOT_OPTION:
-                /* Add file(s) to buffer. This enables processing multiple files
-                 * at once.
-                 *
-                 * Since the non-options (RTGETOPTINIT_FLAGS_OPTS_FIRST) come last when
-                 * processing this loop it's safe to immediately exit on syntax errors
-                 * or showing the help text (see above). */
-                rc = vgsvcToolboxPathBufAddPathEntry(&fileList, ValueUnion.psz);
-                /** @todo r=bird: Nit: creating a list here is not really
-                 *        necessary since you've got one in argv that's
-                 *        accessible via RTGetOpt. */
+                Assert(GetState.iNext);
+                GetState.iNext--;
                 break;
 
@@ -944,23 +932,13 @@
                 return RTGetOptPrintError(ch, &ValueUnion);
         }
+
+        /* All flags / options processed? Bail out here.
+         * Processing the file / directory list comes down below. */
+        if (ch == VINF_GETOPT_NOT_OPTION)
+            break;
     }
 
     if (RT_SUCCESS(rc))
     {
-        /* If not files given add current directory to list. */
-        if (RTListIsEmpty(&fileList))
-        {
-            char szDirCur[RTPATH_MAX + 1];
-            rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
-            if (RT_SUCCESS(rc))
-            {
-                rc = vgsvcToolboxPathBufAddPathEntry(&fileList, szDirCur);
-                if (RT_FAILURE(rc))
-                    RTMsgError("Adding current directory failed, rc=%Rrc\n", rc);
-            }
-            else
-                RTMsgError("Getting current directory failed, rc=%Rrc\n", rc);
-        }
-
         /* Print magic/version. */
         if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE)
@@ -972,16 +950,36 @@
         }
 
-        PVBOXSERVICETOOLBOXPATHENTRY pNodeIt;
-        RTListForEach(&fileList, pNodeIt, VBOXSERVICETOOLBOXPATHENTRY, Node)
-        {
-            if (RTFileExists(pNodeIt->pszName))
+        ch = RTGetOpt(&GetState, &ValueUnion);
+        do
+        {
+            char *pszEntry = NULL;
+
+            if (ch == 0) /* Use current directory if no element specified. */
+            {
+                char szDirCur[RTPATH_MAX + 1];
+                rc = RTPathGetCurrent(szDirCur, sizeof(szDirCur));
+                if (RT_FAILURE(rc))
+                    RTMsgError("Getting current directory failed, rc=%Rrc\n", rc);
+
+                pszEntry = RTStrDup(szDirCur);
+                if (!pszEntry)
+                    RTMsgError("Allocating current directory failed\n");
+            }
+            else
+            {
+                pszEntry = RTStrDup(ValueUnion.psz);
+                if (!pszEntry)
+                    RTMsgError("Allocating directory '%s' failed\n", ValueUnion.psz);
+            }
+
+            if (RTFileExists(pszEntry))
             {
                 RTFSOBJINFO objInfo;
-                int rc2 = RTPathQueryInfoEx(pNodeIt->pszName, &objInfo,
+                int rc2 = RTPathQueryInfoEx(pszEntry, &objInfo,
                                             RTFSOBJATTRADD_UNIX, RTPATH_F_ON_LINK /** @todo Follow link? */);
                 if (RT_FAILURE(rc2))
                 {
                     if (!(fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE))
-                        RTMsgError("Cannot access '%s': No such file or directory\n", pNodeIt->pszName);
+                        RTMsgError("Cannot access '%s': No such file or directory\n", pszEntry);
                     rc = VERR_FILE_NOT_FOUND;
                     /* Do not break here -- process every element in the list
@@ -990,8 +988,6 @@
                 else
                 {
-                    rc2 = vgsvcToolboxPrintFsInfo(pNodeIt->pszName,
-                                                  strlen(pNodeIt->pszName) /* cbName */,
-                                                  fOutputFlags,
-                                                  &objInfo);
+                    rc2 = vgsvcToolboxPrintFsInfo(pszEntry, strlen(pszEntry) /* cbName */,
+                                                  fOutputFlags, &objInfo);
                     if (RT_FAILURE(rc2))
                         rc = rc2;
@@ -1000,9 +996,12 @@
             else
             {
-                int rc2 = vgsvcToolboxLsHandleDir(pNodeIt->pszName, fFlags, fOutputFlags);
+                int rc2 = vgsvcToolboxLsHandleDir(pszEntry, fFlags, fOutputFlags);
                 if (RT_FAILURE(rc2))
                     rc = rc2;
             }
-        }
+
+            RTStrFree(pszEntry);
+        }
+        while ((ch = RTGetOpt(&GetState, &ValueUnion)));
 
         if (fOutputFlags & VBOXSERVICETOOLBOXOUTPUTFLAG_PARSEABLE) /* Output termination. */
@@ -1012,5 +1011,4 @@
         RTMsgError("Failed with rc=%Rrc\n", rc);
 
-    vgsvcToolboxPathBufDestroy(&fileList);
     return RT_SUCCESS(rc) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
 }
