Index: /trunk/src/emx/include/InnoTekLIBC/logstrict.h
===================================================================
--- /trunk/src/emx/include/InnoTekLIBC/logstrict.h	(revision 1322)
+++ /trunk/src/emx/include/InnoTekLIBC/logstrict.h	(revision 1323)
@@ -179,4 +179,7 @@
 #define __LIBC_LOG_GRP_ENV          15
 
+/** Backend IO APIs. */
+#define __LIBC_LOG_GRP_BACK_IO      26
+
 /** Init/Term APIs and Events. */
 #define __LIBC_LOG_GRP_INITTERM     27
Index: /trunk/src/emx/src/lib/sys/logstrict.c
===================================================================
--- /trunk/src/emx/src/lib/sys/logstrict.c	(revision 1322)
+++ /trunk/src/emx/src/lib/sys/logstrict.c	(revision 1323)
@@ -2,12 +2,25 @@
 /** @file
  *
- * LIBC SYS - Debug Logging and Strict Checking Facilities.
- *
- * InnoTek Systemberatung GmbH confidential
+ * LIBC SYS Backend - Debug Logging and Strict Checking Facilities.
  *
  * Copyright (c) 2004 InnoTek Systemberatung GmbH
  * Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
  *
- * All Rights Reserved
+ *
+ * This file is part of InnoTek LIBC.
+ *
+ * InnoTek LIBC is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * InnoTek LIBC is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with InnoTek LIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  *
  */
@@ -53,4 +66,7 @@
 #define INCL_FSMACROS
 #include <os2.h>
+#ifndef HFILE_STDERR
+#define HFILE_STDERR 2
+#endif
 
 
@@ -85,5 +101,5 @@
 static void *   __libc_logDefault(void);
 static int      __libc_logBuildMsg(char *pszMsg, const char *pszFormatMsg, va_list args, const char *pszFormatPrefix, ...) __printflike(4, 5);
-static void     __libc_logWrite(__LIBC_PLOGINST pInst, unsigned fGroupAndFlags, const char *pszMsg, size_t cch);
+static void     __libc_logWrite(__LIBC_PLOGINST pInst, unsigned fGroupAndFlags, const char *pszMsg, size_t cch, int fStdErr);
 static inline unsigned getTimestamp(void);
 static inline unsigned getTid(void);
@@ -415,5 +431,5 @@
             { 1, "future" },            /* 24 */
             { 1, "future" },            /* 25 */
-            { 1, "future" },            /* 26 */
+            { 1, "BACK_IO" },           /* 26 */
             { 1, "INITTERM" },          /* 27 */
             { 1, "BACKEND" },           /* 28 */
@@ -500,6 +516,7 @@
  * @param   pszMsg          String to write.
  * @param   cch             Length of string.
- */
-static void __libc_logWrite(__LIBC_PLOGINST pInst, unsigned fGroupAndFlags, const char *pszMsg, size_t cch)
+ * @param   fStdErr         If set write to standard err too.
+ */
+static void __libc_logWrite(__LIBC_PLOGINST pInst, unsigned fGroupAndFlags, const char *pszMsg, size_t cch, int fStdErr)
 {
     APIRET  rc;
@@ -542,4 +559,42 @@
         DosReleaseMutexSem(pInst->hmtx);
     FS_RESTORE();
+
+    /*
+     * Write to stderr too?
+     */
+    if (fStdErr)
+    {
+        /*
+         * Need to convert '\n' to '\r\n'.
+         */
+        const char *pszNewLine = NULL;
+        do
+        {
+            int cchWrite;
+
+            /* look for next new line */
+            pszNewLine = memchr(pszMsg, '\n', cch);
+            while (pszNewLine > pszMsg && pszNewLine[-1] == '\r')
+            {
+                cchWrite = cch - (pszNewLine - pszMsg + 1);
+                if (cchWrite <= 0)
+                {
+                    pszNewLine = NULL;
+                    break;
+                }
+                pszNewLine = memchr(pszNewLine + 1, '\n', cchWrite);
+            }
+            cchWrite = pszNewLine ? pszNewLine - pszMsg : strnlen(pszMsg, cch);
+            DosWrite(HFILE_STDERR, pszMsg, cchWrite, &cb);
+
+            /* Write newline. */
+            if (!pszNewLine)
+                break; /* done */
+            DosWrite(HFILE_STDERR, "\r\n", 2, &cb);
+            pszMsg = pszNewLine + 1;
+            cch -= cchWrite + 1;
+        } while (cch);
+
+    }
 }
 
@@ -648,5 +703,5 @@
      * Write the message.
      */
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, 0);
     return uTS;
 }
@@ -731,5 +786,5 @@
      * Write the message.
      */
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, 0);
 }
 
@@ -803,5 +858,5 @@
      * Write the message.
      */
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, 0);
 }
 
@@ -855,5 +910,5 @@
      * Write the message.
      */
-    __libc_logWrite(pInst, fGroupAndFlags, pszString, cch);
+    __libc_logWrite(pInst, fGroupAndFlags, pszString, cch, 0);
 }
 
@@ -880,5 +935,4 @@
     char           *pszMsg;
     int             cch;
-    ULONG           cb;
     va_list         args;
     __LIBC_PLOGINST pInst;
@@ -929,5 +983,5 @@
      * NOTE: This buffer *must* be in low memory!!!
      */
-    pszMsg = alloca(CCHTMPMSGBUFFER);
+    pszMsg = alloca(CCHTMPMSGBUFFER + 1);
     if (!pszMsg)
         return;
@@ -939,39 +993,37 @@
     va_start(args, pszFormat);          /* make compiler happy we do it here. */
     cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Assertion Failed!!!\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags));
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+
+    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Function: %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszFunction);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+
+    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: File:     %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszFile);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+
+    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Line:     %d\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), uLine);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+
+    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Expr:     %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszExpression);
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+
+    cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Asrt: ",        uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags));
+    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch, fEnabled);
+    va_end(args);
+
+    /*
+     * Breakpoint. (IBM debugger: T or Ctrl-T to get to caller)
+     */
     if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-
-    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Function: %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszFunction);
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
-    if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-
-    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: File:     %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszFile);
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
-    if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-
-    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Line:     %d\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), uLine);
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
-    if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-
-    cch = __libc_logBuildMsg(pszMsg, "", args, "%08x %02x %02x %04x Asrt: Expr:     %s\n", uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags), pszExpression);
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
-    if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-
-    cch = __libc_logBuildMsg(pszMsg, pszFormat, args, "%08x %02x %02x %04x Asrt: ",        uTS, getTid(), cDepth, __LIBC_LOG_GETGROUP(fGroupAndFlags));
-    __libc_logWrite(pInst, fGroupAndFlags, pszMsg, cch);
-    if (fEnabled)
-        DosWrite(2, pszMsg, cch, &cb);
-    va_end(args);
-
-    /*
-     * Breakpoint. (IBM debugger: T or Ctrl-T to get to caller)
-     */
-    if (fEnabled)
-        __asm__ __volatile__("int $3");
+    {
+        /*
+         * Raise a breakpoint here, that's more convenient in the debugger.
+         * Just press 'T' and you'll be at the LIBC_ASSERT*.
+         */
+        EXCEPTIONREPORTRECORD  XRepRec = {0};
+        XRepRec.ExceptionNum        = XCPT_BREAKPOINT;
+        XRepRec.ExceptionAddress    = (void*)&__libc_LogAssert;
+        if (DosRaiseException(&XRepRec))
+            __asm__ __volatile__("int $3");
+    }
 }
 
