Index: /trunk/include/iprt/env.h
===================================================================
--- /trunk/include/iprt/env.h	(revision 55583)
+++ /trunk/include/iprt/env.h	(revision 55584)
@@ -81,4 +81,13 @@
 
 /**
+ * Resets the environment block to contain zero variables.
+ *
+ * @returns IPRT status code.
+ *
+ * @param   hEnv    Environment block handle.  RTENV_DEFAULT is not supported.
+ */
+RTDECL(int) RTEnvReset(RTENV hEnv);
+
+/**
  * Get the execve/spawnve/main envp.
  *
@@ -112,4 +121,28 @@
  */
 RTDECL(void) RTEnvFreeUtf16Block(PRTUTF16 pwszzBlock);
+
+/**
+ * Get a sorted, UTF-8 environment block.
+ *
+ * The environment block is a sequence of putenv formatted ("NAME=VALUE" or
+ * "NAME") zero terminated strings ending with an empty string (i.e. last string
+ * has two zeros).
+ *
+ * @returns IPRT status code.
+ *
+ * @param   hEnv            Environment block handle.
+ * @param   fSorted         Whether to sort it, this will affect @a hEnv.
+ * @param   ppszzBlock      Where to return the environment block.  This must be
+ *                          freed by calling RTEnvFreeUtf8Block.
+ * @param   pcbBlock        Where to return the size of the block. Optional.
+ */
+RTDECL(int) RTEnvQueryUtf8Block(RTENV hEnv, bool fSorted, char **ppszzBlock, size_t *pcbBlock);
+
+/**
+ * Frees an environment block returned by RTEnvGetUtf8Block().
+ *
+ * @param   pszzBlock       What RTEnvGetUtf8Block returned.  NULL is ignored.
+ */
+RTDECL(void) RTEnvFreeUtf8Block(char *pszzBlock);
 
 /**
Index: /trunk/include/iprt/mangling.h
===================================================================
--- /trunk/include/iprt/mangling.h	(revision 55583)
+++ /trunk/include/iprt/mangling.h	(revision 55584)
@@ -519,4 +519,5 @@
 # define RTEnvExistsUtf8                                RT_MANGLER(RTEnvExistsUtf8)
 # define RTEnvExistEx                                   RT_MANGLER(RTEnvExistEx)
+# define RTEnvFreeUtf8Block                             RT_MANGLER(RTEnvFreeUtf8Block)
 # define RTEnvFreeUtf16Block                            RT_MANGLER(RTEnvFreeUtf16Block)
 # define RTEnvGet                                       RT_MANGLER(RTEnvGet)
@@ -533,4 +534,6 @@
 # define RTEnvPutEx                                     RT_MANGLER(RTEnvPutEx)
 # define RTEnvQueryUtf16Block                           RT_MANGLER(RTEnvQueryUtf16Block)
+# define RTEnvQueryUtf8Block                            RT_MANGLER(RTEnvQueryUtf8Block)
+# define RTEnvReset                                     RT_MANGLER(RTEnvReset)
 # define RTEnvSet                                       RT_MANGLER(RTEnvSet)
 # define RTEnvSetBad                                    RT_MANGLER(RTEnvSetBad)
Index: /trunk/src/VBox/Runtime/generic/env-generic.cpp
===================================================================
--- /trunk/src/VBox/Runtime/generic/env-generic.cpp	(revision 55583)
+++ /trunk/src/VBox/Runtime/generic/env-generic.cpp	(revision 55584)
@@ -348,4 +348,26 @@
 }
 RT_EXPORT_SYMBOL(RTEnvClone);
+
+
+RTDECL(int) RTEnvReset(RTENV hEnv)
+{
+    PRTENVINTERNAL pIntEnv = hEnv;
+    AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE);
+    AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE);
+
+    RTENV_LOCK(pIntEnv);
+
+    size_t iVar = pIntEnv->cVars;
+    pIntEnv->cVars = 0;
+    while (iVar-- > 0)
+    {
+        RTMemFree(pIntEnv->papszEnv[iVar]);
+        pIntEnv->papszEnv[iVar] = NULL;
+    }
+
+    RTENV_UNLOCK(pIntEnv);
+    return VINF_SUCCESS;
+}
+RT_EXPORT_SYMBOL(RTEnvReset);
 
 
@@ -885,5 +907,5 @@
     return rc;
 }
-RT_EXPORT_SYMBOL(RTEnvGetExecEnvP);
+RT_EXPORT_SYMBOL(RTEnvQueryUtf16Block);
 
 
@@ -893,4 +915,94 @@
 }
 RT_EXPORT_SYMBOL(RTEnvFreeUtf16Block);
+
+
+RTDECL(int) RTEnvQueryUtf8Block(RTENV hEnv, bool fSorted, char **ppszzBlock, size_t *pcbBlock)
+{
+    RTENV           hClone  = NIL_RTENV;
+    PRTENVINTERNAL  pIntEnv;
+    int             rc;
+
+    /*
+     * Validate / simplify input.
+     */
+    if (hEnv == RTENV_DEFAULT)
+    {
+        rc = RTEnvClone(&hClone, RTENV_DEFAULT);
+        if (RT_FAILURE(rc))
+            return rc;
+        pIntEnv = hClone;
+    }
+    else
+    {
+        pIntEnv = hEnv;
+        AssertPtrReturn(pIntEnv, VERR_INVALID_HANDLE);
+        AssertReturn(pIntEnv->u32Magic == RTENV_MAGIC, VERR_INVALID_HANDLE);
+        rc = VINF_SUCCESS;
+    }
+
+    RTENV_LOCK(pIntEnv);
+
+    /*
+     * Sort it, if requested.
+     */
+    if (fSorted)
+        RTSortApvShell((void **)pIntEnv->papszEnv, pIntEnv->cVars, rtEnvSortCompare, pIntEnv);
+
+    /*
+     * Calculate the size. We add one extra terminator just to be on the safe side.
+     */
+    size_t cbBlock = 2;
+    for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++)
+        cbBlock += strlen(pIntEnv->papszEnv[iVar]) + 1;
+
+    if (pcbBlock)
+        *pcbBlock = cbBlock - 1;
+
+    /*
+     * Allocate memory and copy out the variables.
+     */
+    char *pszzBlock;
+    char *pszz = pszzBlock = (char *)RTMemAlloc(cbBlock);
+    if (pszz)
+    {
+        size_t cbLeft = cbBlock;
+        for (size_t iVar = 0; iVar < pIntEnv->cVars; iVar++)
+        {
+            size_t cb = strlen(pIntEnv->papszEnv[iVar]) + 1;
+            AssertBreakStmt(cb + 2 <= cbLeft, rc = VERR_INTERNAL_ERROR_3);
+            memcpy(pszz, pIntEnv->papszEnv[iVar], cb);
+            pszz   += cb;
+            cbLeft -= cb;
+        }
+        if (RT_SUCCESS(rc))
+        {
+            pszz[0] = '\0';
+            pszz[1] = '\0'; /* The extra one. */
+        }
+        else
+        {
+            RTMemFree(pszzBlock);
+            pszzBlock = NULL;
+        }
+    }
+    else
+        rc = VERR_NO_MEMORY;
+
+    RTENV_UNLOCK(pIntEnv);
+
+    if (hClone != NIL_RTENV)
+        RTEnvDestroy(hClone);
+    if (RT_SUCCESS(rc))
+        *ppszzBlock = pszzBlock;
+    return rc;
+}
+RT_EXPORT_SYMBOL(RTEnvQueryUtf8Block);
+
+
+RTDECL(void) RTEnvFreeUtf8Block(char *pszzBlock)
+{
+    RTMemFree(RTEnvQueryUtf8Block);
+}
+RT_EXPORT_SYMBOL(RTEnvFreeUtf8Block);
 
 
