Index: trunk/src/emx/src/lib/sys/__dup.c
===================================================================
--- trunk/src/emx/src/lib/sys/__dup.c	(revision 1366)
+++ trunk/src/emx/src/lib/sys/__dup.c	(revision 1367)
@@ -4,4 +4,5 @@
 #include "libc-alias.h"
 #define INCL_FSMACROS
+#define INCL_ERRORS
 #include <os2emx.h>
 #include <errno.h>
@@ -31,8 +32,19 @@
     if (!pFH->pOps)
     {
-        HFILE   hNew = ~0;
+        int     cExpandRetries;
+        HFILE   hNew;
         FS_VAR();
         FS_SAVE_LOAD();
-        rc = DosDupHandle(fh, &hNew);
+        for (cExpandRetries = 0;;)
+        {
+            hNew = ~0;
+            rc = DosDupHandle(fh, &hNew);
+            if (rc != ERROR_TOO_MANY_OPEN_FILES)
+                break;
+            if (cExpandRetries++ >= 3)
+                break;
+            /* autoincrement. */
+            __libc_FHMoreHandles();
+        }   /* ... retry 3 times ... */
         FS_RESTORE();
         fhNew = (int)hNew;
Index: trunk/src/emx/src/lib/sys/__open.c
===================================================================
--- trunk/src/emx/src/lib/sys/__open.c	(revision 1366)
+++ trunk/src/emx/src/lib/sys/__open.c	(revision 1367)
@@ -34,4 +34,5 @@
     HFILE   hFile;
     int     cch;
+    int     cExpandRetries;
     int     failed_open_errno;
     FS_VAR();
@@ -114,35 +115,44 @@
      */
     FS_SAVE_LOAD();
+    for (cExpandRetries = 0;;)
+    {
 #if OFF_MAX > LONG_MAX
-    if (__pfnDosOpenL)
-    {
-        LONGLONG cbInitialTmp = cbInitial;
-        int     cch = strlen(pszFile);
-        char *  pszFile_safe = alloca(cch + 1);
-        if (pszFile_safe)
-        {
-            strcpy(pszFile_safe, pszFile);
-            rc = __pfnDosOpenL((PCSZ)pszFile_safe, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
+        if (__pfnDosOpenL)
+        {
+            LONGLONG cbInitialTmp = cbInitial;
+            int     cch = strlen(pszFile);
+            char *  pszFile_safe = alloca(cch + 1);
+            if (pszFile_safe)
+            {
+                strcpy(pszFile_safe, pszFile);
+                rc = __pfnDosOpenL((PCSZ)pszFile_safe, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
+            }
+            else
+                rc = ERROR_NOT_ENOUGH_MEMORY;
         }
         else
-            rc = ERROR_NOT_ENOUGH_MEMORY;
-    }
-    else
-    {
-        ULONG cbInitialTmp = (ULONG)cbInitial;
-        if (cbInitial > LONG_MAX)
-        {
-            FS_RESTORE();
-            errno = EOVERFLOW;
-            LIBCLOG_RETURN_INT(-1);
-        }
-        rc = DosOpen((PCSZ)pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
-    }
+        {
+            ULONG cbInitialTmp = (ULONG)cbInitial;
+            if (cbInitial > LONG_MAX)
+            {
+                FS_RESTORE();
+                errno = EOVERFLOW;
+                LIBCLOG_RETURN_INT(-1);
+            }
+            rc = DosOpen((PCSZ)pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
+        }
 #else
-    {
-        ULONG cbInitialTmp = cbInitial;
-        rc = DosOpen((PCSZ)pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
-    }
+        {
+            ULONG cbInitialTmp = cbInitial;
+            rc = DosOpen((PCSZ)pszFile, &hFile, &ulAction, cbInitialTmp, flAttr, flOpenFlags, flOpenMode, NULL);
+        }
 #endif
+        /* Check if we're out of handles. */
+        if (rc != ERROR_TOO_MANY_OPEN_FILES)
+            break;
+        if (cExpandRetries++ >= 3)
+            break;
+        __libc_FHMoreHandles();
+    }   /* ... retry 3 times ... */
 
     if (!rc)
Index: trunk/src/emx/src/lib/sys/__pipe.c
===================================================================
--- trunk/src/emx/src/lib/sys/__pipe.c	(revision 1366)
+++ trunk/src/emx/src/lib/sys/__pipe.c	(revision 1367)
@@ -3,4 +3,5 @@
 
 #include "libc-alias.h"
+#define INCL_ERRORS
 #define INCL_DOSQUEUES
 #define INCL_FSMACROS
@@ -14,12 +15,23 @@
 int __pipe(int *two_handles, int pipe_size, PLIBCFH *ppFHRead, PLIBCFH *ppFHWrite)
 {
-    ULONG rc;
+    ULONG   rc;
+    int     cExpandRetries;
     FS_VAR();
 
-    FS_SAVE_LOAD();
     /*
      * Create the pipe
      */
-    rc = DosCreatePipe((PHFILE)&two_handles[0], (PHFILE)&two_handles[1], pipe_size);
+    FS_SAVE_LOAD();
+    for (cExpandRetries = 0;;)
+    {
+        rc = DosCreatePipe((PHFILE)&two_handles[0], (PHFILE)&two_handles[1], pipe_size);
+        if (rc != ERROR_TOO_MANY_OPEN_FILES)
+            break;
+        if (cExpandRetries++ >= 3)
+            break;
+        /* auto increment */
+        __libc_FHMoreHandles();
+    }   /* ... retry 3 times ... */
+
     if (!rc)
     {
