Index: trunk/src/emx/ChangeLog.LIBC
===================================================================
--- trunk/src/emx/ChangeLog.LIBC	(revision 2259)
+++ trunk/src/emx/ChangeLog.LIBC	(revision 2260)
@@ -9,4 +9,13 @@
         o Fixed a few smaller issues.
         o Started fixing exec() backend.
+        o Fixed some more mktime / localtime bugs.
+        o Fixed crash on simple LIBC_ASSERT() caused by NULL format string.
+        o Generate device numbers for devices and pipes too.
+        o Fixed mixup of Dev and Inode during filehandle inheritance.
+        o Fixed __dup and __dup2 bug in relation to the FD_CLOEXEC clearing.
+        o Fixed bug in codepage normalization during setlocale().
+        o Fixed bug in regex where the lock was overwritten after initialization.
+        o Switch the glibc locks to smutex to avoid leaking event semaphores.
+        o Added _smutex_try_request().
 
 2005-07-11: knut st. osmundsen <bird-gccos2-spam@anduin.net>
Index: trunk/src/emx/include/InnoTekLIBC/logstrict.h
===================================================================
--- trunk/src/emx/include/InnoTekLIBC/logstrict.h	(revision 2259)
+++ trunk/src/emx/include/InnoTekLIBC/logstrict.h	(revision 2260)
@@ -154,11 +154,11 @@
 #define LIBCLOG_RETURN_INT(rc)          LIBCLOG_RETURN_MSG((rc), "ret %d (%#x)\n", (rc), (rc))
 /** Macro to log an unsigned int return and do the return. */
-#define LIBCLOG_RETURN_UINT(rc)         LIBCLOG_RETURN_MSG((rc), "ret %u (%#x)\n", (rc), (rc));
+#define LIBCLOG_RETURN_UINT(rc)         LIBCLOG_RETURN_MSG((rc), "ret %u (%#x)\n", (rc), (rc))
 /** Macro to log an long int return and do the return. */
-#define LIBCLOG_RETURN_LONG(rc)         LIBCLOG_RETURN_MSG((rc), "ret %ld (%#lx)\n", (rc), (rc));
+#define LIBCLOG_RETURN_LONG(rc)         LIBCLOG_RETURN_MSG((rc), "ret %ld (%#lx)\n", (rc), (rc))
 /** Macro to log an unsigned long int return and do the return. */
-#define LIBCLOG_RETURN_ULONG(rc)        LIBCLOG_RETURN_MSG((rc), "ret %lu (%#lx)\n", (rc), (rc));
+#define LIBCLOG_RETURN_ULONG(rc)        LIBCLOG_RETURN_MSG((rc), "ret %lu (%#lx)\n", (rc), (rc))
 /** Macro to log a pointer return and do the return. */
-#define LIBCLOG_RETURN_P(rc)            LIBCLOG_RETURN_MSG((rc), "ret %p\n", (void*)(rc));
+#define LIBCLOG_RETURN_P(rc)            LIBCLOG_RETURN_MSG((rc), "ret %p\n", (void*)(rc))
 
 
@@ -182,11 +182,11 @@
 #define LIBCLOG_ERROR_RETURN_INT(rc)          LIBCLOG_ERROR_RETURN_MSG((rc), "ret %d (%#x)\n", (rc), (rc))
 /** Macro to log an unsigned int return user error and do the return. */
-#define LIBCLOG_ERROR_RETURN_UINT(rc)         LIBCLOG_ERROR_RETURN_MSG((rc), "ret %u (%#x)\n", (rc), (rc));
+#define LIBCLOG_ERROR_RETURN_UINT(rc)         LIBCLOG_ERROR_RETURN_MSG((rc), "ret %u (%#x)\n", (rc), (rc))
 /** Macro to log an long int return user error and do the return. */
-#define LIBCLOG_ERROR_RETURN_LONG(rc)         LIBCLOG_ERROR_RETURN_MSG((rc), "ret %ld (%#lx)\n", (rc), (rc));
+#define LIBCLOG_ERROR_RETURN_LONG(rc)         LIBCLOG_ERROR_RETURN_MSG((rc), "ret %ld (%#lx)\n", (rc), (rc))
 /** Macro to log an unsigned long int return user error and do the return. */
-#define LIBCLOG_ERROR_RETURN_ULONG(rc)        LIBCLOG_ERROR_RETURN_MSG((rc), "ret %lu (%#lx)\n", (rc), (rc));
+#define LIBCLOG_ERROR_RETURN_ULONG(rc)        LIBCLOG_ERROR_RETURN_MSG((rc), "ret %lu (%#lx)\n", (rc), (rc))
 /** Macro to log a pointer return user error and do the return. */
-#define LIBCLOG_ERROR_RETURN_P(rc)            LIBCLOG_ERROR_RETURN_MSG((rc), "ret %p\n", (void*)(rc));
+#define LIBCLOG_ERROR_RETURN_P(rc)            LIBCLOG_ERROR_RETURN_MSG((rc), "ret %p\n", (void*)(rc))
 
 
Index: trunk/src/emx/include/sys/smutex.h
===================================================================
--- trunk/src/emx/include/sys/smutex.h	(revision 2259)
+++ trunk/src/emx/include/sys/smutex.h	(revision 2260)
@@ -29,4 +29,9 @@
 }
 
+static __inline__ int _smutex_try_request (__volatile__ _smutex *sem)
+{
+  return __cxchg (sem, 1) == 0;
+}
+
 
 static __inline__ void _smutex_release (__volatile__ _smutex *sem)
Index: trunk/src/emx/src/lib/lgpl/posix/regcomp.c
===================================================================
--- trunk/src/emx/src/lib/lgpl/posix/regcomp.c	(revision 2259)
+++ trunk/src/emx/src/lib/lgpl/posix/regcomp.c	(revision 2260)
@@ -780,5 +780,5 @@
   preg->used = sizeof (re_dfa_t);
 
-  __libc_lock_init (dfa->lock);
+  /* __libc_lock_init (dfa->lock); - why init before memsetting the whole thing? */
 
   err = init_dfa (dfa, length);
@@ -790,4 +790,6 @@
       return err;
     }
+  __libc_lock_init (dfa->lock); /* bird */
+
 #ifdef DEBUG
   dfa->re_str = re_malloc (char, length + 1);
Index: trunk/src/emx/src/lib/lgpl/sysdeps/os2/bits/libc-lock.h
===================================================================
--- trunk/src/emx/src/lib/lgpl/sysdeps/os2/bits/libc-lock.h	(revision 2259)
+++ trunk/src/emx/src/lib/lgpl/sysdeps/os2/bits/libc-lock.h	(revision 2260)
@@ -21,6 +21,23 @@
 #define _BITS_LIBC_LOCK_H 1
 
+#include <InnoTekLIBC/thread.h>
+
+#if 1 /* There is a hev leak problem with using fmutexes. */
+#include <sys/smutex.h>
+
+typedef _smutex                         __libc_lock_t;
+#define __libc_lock_define(CLASS,NAME) \
+  CLASS __libc_lock_t NAME;
+#define __libc_lock_define_initialized(CLASS,NAME) \
+  CLASS __libc_lock_t NAME = 0;
+#define __libc_lock_init(NAME)          (NAME) = 0
+#define __libc_lock_fini(NAME)          (NAME) = 0
+#define __libc_lock_lock(NAME)          _smutex_request(&(NAME))
+#define __libc_lock_trylock(NAME)       (!_smutex_try_request(&(NAME)))
+#define __libc_lock_unlock(NAME)        _smutex_release(&(NAME))
+
+#else
+
 #include <sys/fmutex.h>
-#include <InnoTekLIBC/thread.h>
 
 typedef _fmutex                         __libc_lock_t;
@@ -32,6 +49,7 @@
 #define __libc_lock_fini(NAME)          _fmutex_close(&(NAME))
 #define __libc_lock_lock(NAME)          _fmutex_request(&(NAME), 0)
-#define __libc_lock_trylock(NAME)       _fmutex_reqeust(&(NAME),  _FMR_NOWAIT)
+#define __libc_lock_trylock(NAME)       _fmutex_request(&(NAME),  _FMR_NOWAIT)
 #define __libc_lock_unlock(NAME)        _fmutex_release(&(NAME))
+#endif
 
 
Index: trunk/src/emx/src/lib/locale/setlocale.c
===================================================================
--- trunk/src/emx/src/lib/locale/setlocale.c	(revision 2259)
+++ trunk/src/emx/src/lib/locale/setlocale.c	(revision 2260)
@@ -1311,5 +1311,5 @@
      * Create locale object.
      */
-    if (IS_POSIX_LOCALE(pszLocale))
+    if (IS_C_LOCALE(pszLocale) || IS_POSIX_LOCALE(pszLocale))
         rc = UniCreateLocaleObject(UNI_MBS_STRING_POINTER, gszC, plobj);
     else
@@ -1317,7 +1317,7 @@
     if (rc)
     {
-        LIBC_ASSERTM_FAILED("UniCreateLocaleObject(,%p:{%s},) -> rc=%d\n", pszLocale, pszLocale, rc);
+        LIBCLOG_ERROR("UniCreateLocaleObject(,%p:{%s},) -> rc=%d\n", pszLocale, pszLocale, rc);
         rc = -unierr2errno(rc);
-        LIBCLOG_RETURN_INT(rc);
+        LIBCLOG_ERROR_RETURN_INT(rc);
     }
 
@@ -1333,18 +1333,22 @@
             if (pszCodepageActual)
             {
-                Ucs2Sb(ucsCodepage, pszCodepageActual, UniStrlen(ucsCodepage) + 1);
+                size_t cchCodepageActual = UniStrlen(ucsCodepage);
+                Ucs2Sb(ucsCodepage, pszCodepageActual, cchCodepageActual + 1);
 
                 /*
                  * For some common codeset specs we'll normalize the naming.
                  */
-                if (!strstr(pszCodepageActual,
-                            "ibm-1208" "Ibm-1208" "IBm-1208" "IBM-1208" "IbM-1208" "iBm-1208" "iBM-1208" "ibM-1208"
-                            "utf-8" "Utf-8" "UTf-8" "UTF-8" "UtF-8" "uTf-8" "uTF-8" "utF-8"
-                            "utf8" "Utf8" "UTf8" "UTF8" "UtF8" "uTf8" "uTF8" "utF8"))
+                const char *psz;
+                if ((psz = strstr(pszCodepageActual,
+                                  "ibm-1208!" "Ibm-1208!" "IBm-1208!" "IBM-1208!" "IbM-1208!" "iBm-1208!" "iBM-1208!" "ibM-1208!"
+                                  "utf-8!"    "Utf-8!"    "UTf-8!"    "UTF-8!"    "UtF-8!"    "uTf-8!"    "uTF-8!"    "utF-8!"
+                                  "utf8!"     "Utf8!"     "UTf8!"     "UTF8!"     "UtF8!"     "uTf8!"     "uTF8!"     "utF8!")) != NULL
+                    && psz[cchCodepageActual] == '!')
                     memcpy(pszCodepageActual, "UTF-8", sizeof("UTF-8"));
-                else if (!strstr(pszCodepageActual,
-                                 "ibm-1200" "Ibm-1200" "IBm-1200" "IBM-1200" "IbM-1200" "iBm-1200" "iBM-1200" "ibM-1200"
-                                 "ucs-2" "Ucs-2" "UCs-2" "UCS-2" "UcS-2" "uCs-2" "uCS-2" "ucS-2"
-                                 "ucs2" "Ucs2" "UCs2" "UCS2" "UcS2" "uCs2" "uCS2" "ucS2"))
+                else if ((psz = strstr(pszCodepageActual,
+                                       "ibm-1200!" "Ibm-1200!" "IBm-1200!" "IBM-1200!" "IbM-1200!" "iBm-1200!" "iBM-1200!" "ibM-1200!"
+                                       "ucs-2!"    "Ucs-2!"    "UCs-2!"    "UCS-2!"    "UcS-2!"    "uCs-2!"    "uCS-2!"    "ucS-2!"
+                                       "ucs2!"     "Ucs2!"     "UCs2!"     "UCS2!"     "UcS2!"     "uCs2!"     "uCS2!"     "ucS2!")) != NULL
+                         && psz[cchCodepageActual] == '!')
                     memcpy(pszCodepageActual, "UCS-2", sizeof("UCS-2"));
             }
@@ -1353,10 +1357,10 @@
         }
 
-        LIBC_ASSERTM_FAILED("UniCreateUconvObject(%ls,) -> rc=%d\n", (wchar_t *)ucsCodepage, rc);
+        LIBCLOG_ERROR("UniCreateUconvObject(%ls,) -> rc=%d\n", (wchar_t *)ucsCodepage, rc);
         rc = -unierr2errno(rc);
     }
 
     UniFreeUconvObject(*puobj);
-    LIBCLOG_RETURN_INT(rc);
+    LIBCLOG_ERROR_RETURN_INT(rc);
 }
 
@@ -1423,5 +1427,5 @@
             else
             {
-                LIBC_ASSERTM_FAILED("UniQueryLocaleInfo -> %d\n", rc);
+                LIBCLOG_ERROR("UniQueryLocaleInfo -> %d\n", rc);
                 rc = -unierr2errno(rc);
             }
Index: trunk/src/emx/src/lib/process/tls.c
===================================================================
--- trunk/src/emx/src/lib/process/tls.c	(revision 2259)
+++ trunk/src/emx/src/lib/process/tls.c	(revision 2260)
@@ -88,6 +88,6 @@
     if (__atomic_increment_max(&gcTLSAllocated, __LIBC_TLS_MAX))
     {
-        LIBC_ASSERTM_FAILED("Out of TLS entries! cur=%d max=%d\n", gcTLSAllocated, __LIBC_TLS_MAX);
-        LIBCLOG_RETURN_INT(-1);
+        errno -ENOMEM;
+        LIBCLOG_ERROR_RETURN(-1, "ret -1 - Out of TLS entries! cur=%d max=%d\n", gcTLSAllocated, __LIBC_TLS_MAX);
     }
 
Index: trunk/src/emx/src/lib/sys/DosEx.c
===================================================================
--- trunk/src/emx/src/lib/sys/DosEx.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/DosEx.c	(revision 2260)
@@ -302,5 +302,5 @@
     gcbPools       += cb;
 
-    LIBCLOG_ERROR_RETURN_INT(0);
+    LIBCLOG_RETURN_INT(0);
 }
 
Index: trunk/src/emx/src/lib/sys/__dup.c
===================================================================
--- trunk/src/emx/src/lib/sys/__dup.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/__dup.c	(revision 2260)
@@ -12,4 +12,6 @@
 #include "syscalls.h"
 #include "b_fs.h"
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
+#include <InnoTekLIBC/logstrict.h>
 
 int __dup(int fh)
@@ -64,12 +66,10 @@
 
                 /*
-                 * Clear the FD_CLOEXEC flag as per SuS.
+                 * OS/2 does, as SuS specifies, clear the noinherit flag. So, we update
+                 * the flags of the new handle and in strict mode call __libc_FHSetFlags
+                 * to invoke the out of sync check in there.
                  */
-                unsigned fFlags = pFH->fFlags;
-                if (fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT))
-                {
-                    fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
-                    __libc_FHSetFlags(pFH, hNew,fFlags);
-                }
+                pFHNew->fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
+                LIBC_ASSERT(!__libc_FHSetFlags(pFHNew, hNew, pFHNew->fFlags));
             }
             else
Index: trunk/src/emx/src/lib/sys/__dup2.c
===================================================================
--- trunk/src/emx/src/lib/sys/__dup2.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/__dup2.c	(revision 2260)
@@ -11,4 +11,6 @@
 #include "syscalls.h"
 #include "b_fs.h"
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_IO
+#include <InnoTekLIBC/logstrict.h>
 
 int __dup2(int fh, int fhNew)
@@ -97,12 +99,10 @@
 
                 /*
-                 * Clear the FD_CLOEXEC flag as per SuS.
+                 * OS/2 does, as SuS specifies, clear the noinherit flag. So, we update
+                 * the flags of the new handle and in strict mode call __libc_FHSetFlags
+                 * to invoke the out of sync check in there.
                  */
-                unsigned fFlags = pFH->fFlags;
-                if (fFlags & ((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT))
-                {
-                    fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
-                    __libc_FHSetFlags(pFH, hNew,fFlags);
-                }
+                pFHNew->fFlags &= ~((FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT) | O_NOINHERIT);
+                LIBC_ASSERT(!__libc_FHSetFlags(pFHNew, hNew, pFHNew->fFlags));
             }
             else
Index: trunk/src/emx/src/lib/sys/__spawnve.c
===================================================================
--- trunk/src/emx/src/lib/sys/__spawnve.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/__spawnve.c	(revision 2260)
@@ -502,5 +502,9 @@
                          * Ignore SIGCHLD signal.
                          */
-
+                        /** @todo proxy job control */
+                        bsd_signal(SIGCHLD, SIG_DFL);
+                        bsd_signal(SIGSTOP, SIG_DFL);
+                        bsd_signal(SIGTSTP, SIG_DFL);
+                        bsd_signal(SIGCONT, SIG_DFL);
 
                         /*
@@ -509,5 +513,4 @@
                         pid_t pid = resc.codeTerminate;
                         LIBCLOG_MSG("Calling __libc_Back_processWait(P_PID,%d,,WEXITED,NULL)\n", pid);
-                        pid_t pidEnded;
                         for (;;)
                         {
@@ -515,11 +518,11 @@
                             do
                                 /** @todo proxy job control */
-                                pidEnded = __libc_Back_processWait(P_PID, pid, &SigInfo, WEXITED, NULL);
-                            while (pidEnded == -EINTR);
-                            if (pidEnded <= 0)
+                                rc = __libc_Back_processWait(P_PID, pid, &SigInfo, WEXITED, NULL);
+                            while (rc == -EINTR);
+                            if (rc < 0)
                                 break;
-                            LIBCLOG_MSG("__libc_Back_processWait(P_PID,%d,,WEXITED,NULL) returned pidEnded=%d si_code=%d si_status=%#x (%d)\n",
-                                        pid, pidEnded, SigInfo.si_code, SigInfo.si_status, SigInfo.si_status);
-                            LIBC_ASSERTM(pidEnded == pid, "Expected pid %d and got %d!\n", pid, pidEnded);
+                            LIBCLOG_MSG("__libc_Back_processWait(P_PID,%d,,WEXITED,NULL) returned %d si_code=%d si_status=%#x (%d)\n",
+                                        pid, rc, SigInfo.si_code, SigInfo.si_status, SigInfo.si_status);
+                            LIBC_ASSERTM(SigInfo.si_pid == pid, "Expected pid %d and got %d!\n", pid, SigInfo.si_pid);
                             if (    SigInfo.si_code == CLD_STOPPED
                                 ||  SigInfo.si_code == CLD_CONTINUED)
@@ -568,5 +571,5 @@
                         }
 
-                        LIBC_ASSERTM_FAILED("__libc_Back_processWait(P_PID,%d,,WEXITED,NULL) returned pidEnded=%d\n", pid, pidEnded);
+                        LIBC_ASSERTM_FAILED("__libc_Back_processWait(P_PID,%d,,WEXITED,NULL) returned %d\n", pid, rc);
                         __libc_spmTerm(__LIBC_EXIT_REASON_KILL + SIGABRT, 123);
                         for (;;)
Index: trunk/src/emx/src/lib/sys/b_ioFileOpen.c
===================================================================
--- trunk/src/emx/src/lib/sys/b_ioFileOpen.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/b_ioFileOpen.c	(revision 2260)
@@ -174,16 +174,4 @@
         ULONG   fulType;
         ULONG   fulDevFlags;
-        dev_t   Dev;
-        ino_t   Inode;
-
-        /*
-         * If a new file the unix EAs needs to be established.
-         */
-        if (   (ulAction == FILE_CREATED)
-            && !__libc_gfNoUnix)
-            __libc_back_fsUnixAttribsSet(hFile, szNativePath, Mode, &Dev, &Inode);
-        else
-            Dev = __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
-
 
         /*
@@ -193,4 +181,6 @@
         if (!rc)
         {
+            dev_t   Dev;
+            ino_t   Inode;
             switch (fulType & 0xff)
             {
@@ -198,10 +188,29 @@
                 case HANDTYPE_FILE:
                     fLibc |= F_FILE;
+                    /* If a new file the unix EAs needs to be established. */
+                    if (   (ulAction == FILE_CREATED)
+                        && !__libc_gfNoUnix)
+                        __libc_back_fsUnixAttribsSet(hFile, szNativePath, Mode, &Dev, &Inode);
+                    else
+                        Dev = __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
                     break;
                 case HANDTYPE_DEVICE:
                     fLibc |= F_DEV;
+                    if (!(fulDevFlags & 0xf))
+                        Dev = makedev('c', 0);
+                    else if (fulDevFlags & 1 /*KBD*/)
+                        Dev = makedev('c', 1);
+                    else if (fulDevFlags & 2 /*SCR*/)
+                        Dev = makedev('c', 2);
+                    else if (fulDevFlags & 4 /*NUL*/)
+                        Dev = makedev('c', 4);
+                    else /*if (fulDevFlags & 8 / *CLK* /)*/
+                        Dev = makedev('c', 8);
+                    __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
                     break;
                 case HANDTYPE_PIPE:
                     fLibc |= F_PIPE;
+                    Dev = makedev('p', 0);
+                    __libc_back_fsPathCalcInodeAndDev(szNativePath, &Inode);
                     break;
             }
Index: trunk/src/emx/src/lib/sys/filehandles.c
===================================================================
--- trunk/src/emx/src/lib/sys/filehandles.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/filehandles.c	(revision 2260)
@@ -193,6 +193,6 @@
                             return -1;
                         }
-                        pFH->Dev = u.pStds->aHandles[i].Inode;
-                        pFH->Inode = u.pStds->aHandles[i].Dev;
+                        pFH->Inode = u.pStds->aHandles[i].Inode;
+                        pFH->Dev = u.pStds->aHandles[i].Dev;
                         pFH->pFsInfo = __libc_back_fsInfoObjByDev(pFH->Dev);
                     }
@@ -902,4 +902,5 @@
 int __libc_FHClose(int fh)
 {
+    LIBCLOG_ENTER("fh=%d\n", fh);
     __LIBC_PFH  pFH;
     int         rc;
@@ -907,5 +908,5 @@
 
     if (_fmutex_request(&gmtx, 0))
-        return -1;
+        LIBCLOG_ERROR_RETURN(-1, "ret -1 - fh=%d is not opened according to our table!\n", fh);
 
     /*
@@ -914,8 +915,7 @@
     if (!fhGet(fh))
     {
-        LIBC_ASSERTM_FAILED("fh=%d is not opened according to our table!\n", fh);
         _fmutex_release(&gmtx);
         errno = EBADF;
-        return -1;
+        LIBCLOG_ERROR_RETURN(-1, "ret -1 - fh=%d is not opened according to our table!\n", fh);
     }
 
@@ -967,13 +967,11 @@
     _fmutex_release(&gmtx);
 
-    if (rc)
-    {
-        if (rc > 0)
-            _sys_set_errno(rc);
-        else
-            errno = -rc;
-    }
-
-    return rc;
+    if (!rc)
+        LIBCLOG_RETURN_INT(0);
+    if (rc > 0)
+        _sys_set_errno(rc);
+    else
+        errno = -rc;
+    LIBCLOG_ERROR_RETURN_INT(rc);
 }
 
@@ -1022,4 +1020,5 @@
             ULONG       fulMode;
             unsigned    fLibc;
+            dev_t       Dev = 0;
 
             /*
@@ -1045,7 +1044,18 @@
                     fLibc = F_DEV;
                     /* @todo inherit O_NDELAY */
+                    if (!(fulDevFlags & 0xf))
+                        Dev = makedev('c', 0);
+                    else if (fulDevFlags & 1 /*KBD*/)
+                        Dev = makedev('c', 1);
+                    else if (fulDevFlags & 2 /*SCR*/)
+                        Dev = makedev('c', 2);
+                    else if (fulDevFlags & 4 /*NUL*/)
+                        Dev = makedev('c', 4);
+                    else /*if (fulDevFlags & 8 / *CLK* /)*/
+                        Dev = makedev('c', 8);
                     break;
                 case HANDTYPE_PIPE:
                     fLibc = F_PIPE;
+                    Dev = makedev('p', 0);
                     break;
             }
@@ -1079,5 +1089,7 @@
              */
             rc = fhAllocate(fh, fLibc, sizeof(LIBCFH), NULL, &pFH, NULL, 1);
-            if (rc)
+            if (!rc)
+                pFH->Dev = Dev;
+            else
                 pFH = NULL;
         }
@@ -1164,5 +1176,5 @@
     ULONG   fulState;
     FS_VAR();
-    LIBC_ASSERT(((fFlags & O_NOINHERIT) == 0) == ((fFlags & (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)) != 0));
+    LIBC_ASSERT(((fFlags & O_NOINHERIT) != 0) == ((fFlags & (FD_CLOEXEC << __LIBC_FH_FDFLAGS_SHIFT)) != 0));
 
     FS_SAVE_LOAD();
Index: trunk/src/emx/src/lib/sys/fs.c
===================================================================
--- trunk/src/emx/src/lib/sys/fs.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/fs.c	(revision 2260)
@@ -1037,5 +1037,5 @@
              * getting the caseing resolved.)
              */
-            LIBC_ASSERT(psz - pszNativePath == cchNativePath);
+            //LIBC_ASSERT(psz - pszNativePath == cchNativePath); - figure this one.
             PFILEFINDBUF4 pFindBuf = (PFILEFINDBUF4)pachBuffer;
             ULONG cFiles = 1;
@@ -1548,5 +1548,8 @@
     }
     else
-        LIBC_ASSERT(chDrv == '/' || chDrv == '\\');
+    {
+        LIBC_ASSERTM(major(Dev) != 'V', "Dev=%#x major=%#x (%c) chDrv=%c\n", Dev, major(Dev), major(Dev), chDrv);
+        LIBC_ASSERTM(major(Dev) != 'U' || minor(chDrv) == 0, "Dev=%#x major=%#x (%c)\n", Dev, major(Dev), major(Dev));
+    }
 
     return pFsInfo;
Index: trunk/src/emx/src/lib/sys/logstrict.c
===================================================================
--- trunk/src/emx/src/lib/sys/logstrict.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/logstrict.c	(revision 2260)
@@ -2096,9 +2096,18 @@
 static int      __libc_logVSNPrintf(char *pszBuffer, size_t cchBuffer, const char *pszFormat, va_list args)
 {
-    int             rc;
-    int             cch;
+    int rc;
+    int cch;
     __LIBC_XCPTREG  XcptRegRec = { { (void *)-1, __libc_logXcptHandler }, };
     FS_VAR();
 
+    /* Ignore NULL format string. */
+    if (!pszFormat)
+    {
+        if (cchBuffer)
+            *pszBuffer = '\0';
+        return 0;
+    }
+
+    /* Get along with the formatting. */
     FS_SAVE_LOAD();
     DosSetExceptionHandler(&XcptRegRec.RegRec);
Index: trunk/src/emx/src/lib/sys/pathrewrite.c
===================================================================
--- trunk/src/emx/src/lib/sys/pathrewrite.c	(revision 2259)
+++ trunk/src/emx/src/lib/sys/pathrewrite.c	(revision 2260)
@@ -226,8 +226,5 @@
             ||  !(paRules[i].fFlags & (__LIBC_PRWF_TYPE_FILE | __LIBC_PRWF_TYPE_DIR))
             ||  (paRules[i].fFlags & ~(__LIBC_PRWF_TYPE_FILE | __LIBC_PRWF_TYPE_DIR | __LIBC_PRWF_CASE_SENSITIVE | __LIBC_PRWF_CASE_INSENSITIVE)))
-        {
-            LIBC_ASSERTM_FAILED("rule %d: Invalid flags %#x\n", i, paRules[i].fFlags);
-            LIBCLOG_ERROR_RETURN_INT(-1);
-        }
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: Invalid flags %#x\n", i, paRules[i].fFlags);
 
         /*
@@ -236,14 +233,8 @@
         cch = strlen(paRules[i].pszFrom);
         if (cch != paRules[i].cchFrom)
-        {
-            LIBC_ASSERTM_FAILED("rule %d: invalid FROM length. actual=%d given=%d\n", i, cch, paRules[i].cchFrom);
-            LIBCLOG_ERROR_RETURN_INT(-1);
-        }
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: invalid FROM length. actual=%d given=%d\n", i, cch, paRules[i].cchFrom);
         if (    paRules[i].pszFrom[cch - 1] == '\\'
             ||  paRules[i].pszFrom[cch - 1] == '/')
-        {
-            LIBC_ASSERTM_FAILED("rule %d: invalid FROM ends with slash.\n",i );
-            LIBCLOG_ERROR_RETURN_INT(-1);
-        }
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: invalid FROM ends with slash.\n",i );
 
         /*
@@ -252,16 +243,9 @@
         cch = strlen(paRules[i].pszTo);
         if (cch != paRules[i].cchTo || !cch)
-        {
-            LIBC_ASSERTM_FAILED("rule %d: invalid TO length. actual=%d given=%d\n", i, cch, paRules[i].cchTo);
-            LIBCLOG_ERROR_RETURN_INT(-1);
-        }
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: invalid TO length. actual=%d given=%d\n", i, cch, paRules[i].cchTo);
         if (    !(cch == 1  || (cch == 3 && paRules[i].pszTo[1] == ':'))
             && (    paRules[i].pszTo[cch - 1] == '\\'
                 ||  paRules[i].pszTo[cch - 1] == '/') )
-        {
-            LIBC_ASSERTM_FAILED("rule %d: invalid TO ends with slash.\n", i);
-            LIBCLOG_ERROR_RETURN_INT(-1);
-        }
-
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: invalid TO ends with slash.\n", i);
 
         /*
@@ -283,8 +267,5 @@
             cch    = pszEnd - psz;
             if (cch > 255)
-            {
-                LIBC_ASSERTM_FAILED("rule %d: path component is too long (%d bytes, 255 is max)\n", i, cch);
-                LIBCLOG_ERROR_RETURN_INT(-1);
-            }
+                LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: path component is too long (%d bytes, 255 is max)\n", i, cch);
 
             /*
@@ -314,8 +295,5 @@
             if (    (pEntry->fFlags & DIRENTRY_FLAGS_CASE)
                 !=  (paRules[i].fFlags & __LIBC_PRWF_CASE_SENSITIVE ? DIRENTRY_FLAGS_CASE : 0))
-            {
-                LIBC_ASSERTM_FAILED("rule %d: collides with an exiting rule in terms of case sensitivity.\n", i);
-                LIBCLOG_ERROR_RETURN_INT(-1);
-            }
+                LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: collides with an exiting rule in terms of case sensitivity.\n", i);
 
             /*
@@ -326,8 +304,5 @@
             {
                 if (pEntry->fType != (paRules[i].fFlags & __LIBC_PRWF_TYPE_FILE ? DIRENTRY_TYPE_FILE : DIRENTRY_TYPE_DIR))
-                {
-                    LIBC_ASSERTM_FAILED("rule %d: collides with existing rule for '%s' (not same type)\n", i, paRules[i].pszFrom);
-                    LIBCLOG_ERROR_RETURN_INT(-1);
-                }
+                    LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: collides with existing rule for '%s' (not same type)\n", i, paRules[i].pszFrom);
 
                 __LIBC_PPATHREWRITE pRule = pEntry->fType == DIRENTRY_TYPE_FILE
@@ -336,9 +311,6 @@
                     &&  (   pRule->cchTo != paRules[i].cchTo
                          || memicmp(pRule->pszTo, paRules[i].pszTo, paRules[i].cchTo)))
-                {
-                    LIBC_ASSERTM_FAILED("rule %d: collides with existing rule for '%s', different rewriting: existing='%s' new='%s'\n",
-                                        i, paRules[i].pszFrom, pRule->pszTo, paRules[i].pszTo);
-                    LIBCLOG_ERROR_RETURN_INT(-1);
-                }
+                    LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: collides with existing rule for '%s', different rewriting: existing='%s' new='%s'\n",
+                                         i, paRules[i].pszFrom, pRule->pszTo, paRules[i].pszTo);
                 break;                  /* excellent, complete match of just an simple subdirectory. */
             }
@@ -349,8 +321,5 @@
              */
             if (pEntry->fType != DIRENTRY_TYPE_DIR)
-            {
-                LIBC_ASSERTM_FAILED("rule %d: collides with a file rule for '%s'\n", i, pEntry->u.pFile->pszFrom);
-                LIBCLOG_ERROR_RETURN_INT(-1);
-            }
+                LIBCLOG_ERROR_RETURN(-1, "ret -1 - rule %d: collides with a file rule for '%s'\n", i, pEntry->u.pFile->pszFrom);
             psz  = pszEnd + 1;
             pDir = pEntry->u.pDir;
@@ -672,8 +641,5 @@
      */
     if (!pszPath || !*pszPath)
-    {
-        LIBC_ASSERTM_FAILED("bad path\n");
-        LIBCLOG_ERROR_RETURN_INT(-1);
-    }
+        LIBCLOG_ERROR_RETURN(-1, "ret -1 - bad path\n");
 
     /*
@@ -697,5 +663,5 @@
         if (cch > 255)
         {
-            LIBC_ASSERTM_FAILED("path component is too long (%d bytes, 255 is max)\n", cch);
+            LIBCLOG_ERROR_RETURN(-1, "ret -1 - path component is too long (%d bytes, 255 is max)\n", cch);
             break;                      /* path component is to long, we don't accept rules like this one!! */
         }
@@ -755,8 +721,5 @@
                     {
                         if (cchBuf < cch)
-                        {
-                            LIBC_ASSERTM_FAILED("Buffer is too small (%d < %d)\n", cchBuf, cch);
-                            LIBCLOG_ERROR_RETURN_INT(-1);
-                        }
+                            LIBCLOG_ERROR_RETURN(-1, "ret -1 - Buffer is too small (%d < %d)\n", cchBuf, cch);
                         memcpy(pszBuf, pRule->pszTo, cch);
                         LIBCLOG_MSG("rewritten: '%s' (complete)\n", pszBuf);
@@ -785,8 +748,5 @@
             char *pszBufIn = pszBuf;
             if (cchBuf < cchTotal)
-            {
-                LIBC_ASSERTM_FAILED("Buffer is too small (%d < %d)\n", cchBuf, cchTotal);
-                LIBCLOG_ERROR_RETURN_INT(-1);
-            }
+                LIBCLOG_ERROR_RETURN(-1, "ret -1 - Buffer is too small (%d < %d)\n", cchBuf, cchTotal);
             memcpy(pszBuf, pRuleBest->pszTo, pRuleBest->cchTo);
             pszBuf += pRuleBest->cchTo;
Index: trunk/src/emx/src/lib/time/gmtime.c
===================================================================
--- trunk/src/emx/src/lib/time/gmtime.c	(revision 2259)
+++ trunk/src/emx/src/lib/time/gmtime.c	(revision 2260)
@@ -37,22 +37,28 @@
 
     {
-        int lo, hi, i;
-
         /* Find an i such that _year_day[i] <= days < _year_day[i+1]. */
-
-        lo = 0; hi = _YEARS - 1;
-        for (;;)
+        int hi = _YEARS - 1;
+        if ((int)_year_day[hi] < days)
+            LIBCLOG_ERROR_RETURN_P(NULL);
+        else if ((int)_year_day[0] > days)
+            LIBCLOG_ERROR_RETURN_P(NULL);
+        else
         {
-            i = (lo + hi) / 2;
-            if (_year_day[i] > days)
-                hi = i - 1;
-            else if (_year_day[i+1] <= days)
-                lo = i + 1;
-            else
-                break;
+            int i = 0;
+            int lo = 0;
+            for (;;)
+            {
+                i = (lo + hi) / 2;
+                if (_year_day[i] > days)
+                    hi = i - 1;
+                else if (_year_day[i+1] <= days)
+                    lo = i + 1;
+                else
+                    break;
+            }
+            dst->tm_year = i;
+            days -= _year_day[i];
+            dst->tm_yday = days;
         }
-        dst->tm_year = i;
-        days -= _year_day[i];
-        dst->tm_yday = days;
     }
 
Index: trunk/src/emx/src/lib/time/mktime.c
===================================================================
--- trunk/src/emx/src/lib/time/mktime.c	(revision 2259)
+++ trunk/src/emx/src/lib/time/mktime.c	(revision 2260)
@@ -14,5 +14,5 @@
                   t->tm_isdst, /*t->tm_gmtoff*/-2, /*t->tm_zone*/(void *)NULL, /*t->tm_zone*/"");
     time64_t t64 = _mktime64(t);
-    if (t64 != -1 && t64 > TIME_T_MIN && t64 <= TIME_T_MAX)
+    if (t64 != -1 && t64 >= TIME_T_MIN && t64 <= TIME_T_MAX)
     {
         time_t t32 = (time_t)t64;
@@ -54,6 +54,6 @@
     }
 
-    t1 = (time_t)__mktime64(t);
-    if (t1 == (time_t)-1)
+    t1 = __mktime64(t);
+    if (t1 == -1)
         return -1;
     dst = _loc2gmt64(&t1, t->tm_isdst);
