Index: /trunk/libc/include/klibc/backend.h
===================================================================
--- /trunk/libc/include/klibc/backend.h	(revision 2917)
+++ /trunk/libc/include/klibc/backend.h	(revision 2918)
@@ -144,10 +144,9 @@
  *
  * @returns 0 on success.
- * @returns -EINVAL if the pReqTS is invalid.
  * @returns -EINTR if the interrupted by signal.
-
+ *
  * @param   u64NanoReq      Time to sleep, in nano seconds.
  * @param   pu64NanoRem     Where to store remaining time (also nano seconds).
-
+ *
  * @remark  For relativly small sleeps this api temporarily changes the thread
  *          priority to timecritical (that is, if it's in the normal or idle priority
@@ -635,4 +634,14 @@
  */
 int  __libc_Back_ldrOpen(const char *pszLibrary, int fFlags, void **ppvModule, char *pszError, size_t cchError);
+
+/**
+ * Get the name of the executable.
+ *
+ * @returns 0 on success.
+ * @returns Negated error code (errno.h) on failure.
+ * @param   pszNameBuf  Where to store the name.
+ * @param   cchNameBuf  The size of the buffer.
+ */
+int __libc_Back_ldrExeName(char *pszNameBuf, size_t cchNameBuf);
 
 /**
@@ -1137,4 +1146,14 @@
  */
 int __libc_Back_processSetPriority(int iWhich, id_t idWho, int iPrio);
+
+/**
+ * Get the resource usage of the process or the child processes.
+ *
+ * @returns 0 on success.
+ * @returns Neagted error code (errno.h) on failure.
+ * @param   iWho        Who to get the resource usage of, RUSAGE_SELF or RUSAGE_CHILDREN.
+ * @param   pUsage      Where to store the resource usage.
+ */
+int __libc_Back_processGetResourceUsage(int iWho, struct rusage *pUsage);
 
 /**
Index: /trunk/libc/include/klibc/logstrict.h
===================================================================
--- /trunk/libc/include/klibc/logstrict.h	(revision 2917)
+++ /trunk/libc/include/klibc/logstrict.h	(revision 2918)
@@ -237,4 +237,6 @@
 /** Other I/O APIs. */
 #define __LIBC_LOG_GRP_IO           4
+/** Other Filesystem APIs. */
+#define __LIBC_LOG_GRP_FS           4 /** @todo fixme */
 /** String APIs. */
 #define __LIBC_LOG_GRP_STRING       5
Index: /trunk/libc/src/kNIX/Makefile.kmk
===================================================================
--- /trunk/libc/src/kNIX/Makefile.kmk	(revision 2917)
+++ /trunk/libc/src/kNIX/Makefile.kmk	(revision 2918)
@@ -65,4 +65,5 @@
     $(PATH_LIBC_SRC)/kNIX/heap.c \
     $(PATH_LIBC_SRC)/kNIX/heapdata.c \
+    $(PATH_LIBC_SRC)/kNIX/_os_version.c \
 
 #    $(PATH_LIBC_SRC)/kNIX/b_ioDuplicate.c \
@@ -92,4 +93,5 @@
     $(PATH_LIBC_SRC)/kNIX/os2/b_ioFileOpen.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_ldrClose.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/b_ldrExeName.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_ldrOpen.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_ldrSymbol.c \
@@ -102,4 +104,5 @@
     $(PATH_LIBC_SRC)/kNIX/os2/b_processExit.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_processGetPriority.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/b_processGetResourceUsage.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_processSetPriority.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_processWait.c \
@@ -122,6 +125,4 @@
     $(PATH_LIBC_SRC)/kNIX/os2/b_timeHighResNano.c \
     $(PATH_LIBC_SRC)/kNIX/os2/b_timeSet.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/clock.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/core.c \
     $(PATH_LIBC_SRC)/kNIX/os2/DosAllocMemEx.c \
     $(PATH_LIBC_SRC)/kNIX/os2/DosAllocSharedMemEx.c \
@@ -139,12 +140,9 @@
     $(PATH_LIBC_SRC)/kNIX/os2/DosOpenMutexSemEx.c \
     $(PATH_LIBC_SRC)/kNIX/os2/exceptions.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/execname.c \
     $(PATH_LIBC_SRC)/kNIX/os2/FastInfoBlocks.c \
     $(PATH_LIBC_SRC)/kNIX/os2/filefind.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/filesys.c \
     $(PATH_LIBC_SRC)/kNIX/os2/fhOS2File.c \
     $(PATH_LIBC_SRC)/kNIX/os2/fs-os2.c \
     $(PATH_LIBC_SRC)/kNIX/os2/fsync.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/getppid.c \
     $(PATH_LIBC_SRC)/kNIX/os2/heaphigh.c \
     $(PATH_LIBC_SRC)/kNIX/os2/hooks.c \
@@ -159,5 +157,4 @@
     $(PATH_LIBC_SRC)/kNIX/os2/sharedpm.c \
     $(PATH_LIBC_SRC)/kNIX/os2/signals.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/sleep2.c \
     $(PATH_LIBC_SRC)/kNIX/os2/sysv_sem.c \
     $(PATH_LIBC_SRC)/kNIX/os2/sysv_shm.c \
@@ -166,18 +163,4 @@
     $(PATH_LIBC_SRC)/kNIX/os2/tcpipver43.c \
     $(PATH_LIBC_SRC)/kNIX/os2/timebomb.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/uflags.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/umask.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__chmod.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__dup.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__dup2.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__init.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__initdll.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__ioctl1.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__ioctl2.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__os_version.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__pipe.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__select.c \
-    $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \
     $(PATH_LIBC_SRC)/kNIX/os2/386/appinit.s \
     $(PATH_LIBC_SRC)/kNIX/os2/386/thunk0.s \
@@ -185,4 +168,17 @@
     $(PATH_LIBC_SRC)/kNIX/os2/386/unwind.s \
     $(PATH_LIBC_SRC)/kNIX/os2/386/__init_environ.s \
+    $(PATH_LIBC_SRC)/kNIX/os2/umask.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__chmod.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__spawnve.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__read_kbd.c
+TODO= \
+    $(PATH_LIBC_SRC)/kNIX/os2/__init.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__initdll.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__dup.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__dup2.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__ioctl1.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__ioctl2.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__pipe.c \
+    $(PATH_LIBC_SRC)/kNIX/os2/__select.c \
 
 
Index: /trunk/libc/src/kNIX/_os_version.c
===================================================================
--- /trunk/libc/src/kNIX/_os_version.c	(revision 2918)
+++ /trunk/libc/src/kNIX/_os_version.c	(revision 2918)
@@ -0,0 +1,5 @@
+/* sys/os_ver.c (emx+gcc) -- Copyright (c) 1992-1995 by Eberhard Mattes */
+
+unsigned char _osmajor = 0;
+unsigned char _osminor = 0;
+
Index: unk/libc/src/kNIX/os2/__os_version.c
===================================================================
--- /trunk/libc/src/kNIX/os2/__os_version.c	(revision 2917)
+++ 	(revision )
@@ -1,5 +1,0 @@
-/* sys/os_ver.c (emx+gcc) -- Copyright (c) 1992-1995 by Eberhard Mattes */
-
-unsigned char _osmajor = 0;
-unsigned char _osminor = 0;
-
Index: /trunk/libc/src/kNIX/os2/__spawnve.c
===================================================================
--- /trunk/libc/src/kNIX/os2/__spawnve.c	(revision 2917)
+++ /trunk/libc/src/kNIX/os2/__spawnve.c	(revision 2918)
@@ -31,8 +31,5 @@
 #include "kNIX.h"
 /** @todo Cleanup __spawnve.c properly! */
-#include "b_signal.h"
-#include "b_process.h"
 #include <emx/syscalls.h>
-#include <InnoTekLIBC/sharedpm.h>
 #define __LIBC_LOG_GROUP    __LIBC_LOG_GRP_PROCESS
 #include <klibc/logstrict.h>
Index: /trunk/libc/src/kNIX/os2/b_fsStat.c
===================================================================
--- /trunk/libc/src/kNIX/os2/b_fsStat.c	(revision 2917)
+++ /trunk/libc/src/kNIX/os2/b_fsStat.c	(revision 2918)
@@ -200,5 +200,5 @@
              */
             bzero(pStatFs, sizeof(*pStatFs));
-            strncpy(pStatFs->f_fstypename, (char *)&pfsq->szName[pfsq->cbName + 1] /* FSDName */, sizeof(pStatFs->f_fstypename) - 1);
+            strncat(pStatFs->f_fstypename, (char *)&pfsq->szName[pfsq->cbName + 1] /* FSDName */, sizeof(pStatFs->f_fstypename) - 1);
             int fDefDevName = 0;
             if (/*!strcmp(pStatFs->f_fstypename, "LAN") && */pfsq->cbFSAData)
Index: /trunk/libc/src/kNIX/os2/b_ldrExeName.c
===================================================================
--- /trunk/libc/src/kNIX/os2/b_ldrExeName.c	(revision 2918)
+++ /trunk/libc/src/kNIX/os2/b_ldrExeName.c	(revision 2918)
@@ -0,0 +1,55 @@
+/* $Id: $ */
+/** @file
+ *
+ * kNIX - _execname(), OS/2.
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "kNIX.h"
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_LDR
+#include <klibc/logstrict.h>
+
+/**
+ * Get the name of the executable.
+ *
+ * @returns 0 on success.
+ * @returns Negated error code (errno.h) on failure.
+ * @param   pszNameBuf  Where to store the name.
+ * @param   cchNameBuf  The size of the buffer.
+ */
+int __libc_Back_ldrExeName(char *pszNameBuf, size_t cchNameBuf)
+{
+    LIBCLOG_ENTER("pszNameBuf=%p cchNameBuf=%zd\n", (void *)pszNameBuf, cchNameBuf);
+
+    if (cchNameBuf == 0)
+        LIBCLOG_ERROR_RETURN_INT(-EINVAL);
+
+    FS_VAR_SAVE_LOAD();
+    int rc = DosQueryModuleName(fibGetExeHandle(), cchNameBuf, pszNameBuf);
+    if (!rc)
+        LIBCLOG_RETURN_MSG(0, "ret %d - pszNameBuf=%p:{%s}\n", rc, (void *)pszNameBuf, pszNameBuf);
+
+    pszNameBuf[0] = '\0';
+    rc = -__libc_back_native2errno(rc);
+    LIBCLOG_ERROR_RETURN_INT(rc);
+}
+
Index: /trunk/libc/src/kNIX/os2/b_processClock.c
===================================================================
--- /trunk/libc/src/kNIX/os2/b_processClock.c	(revision 2918)
+++ /trunk/libc/src/kNIX/os2/b_processClock.c	(revision 2918)
@@ -0,0 +1,35 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - clock().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "kNIX.h"
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
+#include <klibc/logstrict.h>
+
+clock_t __libc_Back_processClock(void)
+{
+
+}
+
Index: /trunk/libc/src/kNIX/os2/b_processGetResourceUsage.c
===================================================================
--- /trunk/libc/src/kNIX/os2/b_processGetResourceUsage.c	(revision 2918)
+++ /trunk/libc/src/kNIX/os2/b_processGetResourceUsage.c	(revision 2918)
@@ -0,0 +1,204 @@
+/* $Id: $ */
+/** @file
+ *
+ * kNIX - getrusage().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "kNIX.h"
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_BACK_PROCESS
+#include <klibc/logstrict.h>
+
+/**
+ * Worker for __libc_Back_processGetResourceUsage which tried to do
+ * the job using a buffer of a certain size.
+ */
+static int __libc_Back_processGetResourceUsageSub(int iWho, struct rusage *pUsage, size_t cbBuf)
+{
+    /*
+     * Allocate the buffer.
+     */
+    void *pvFree = NULL;
+    QSPTRREC *pPtrRec;
+    if (cbBuf < 32*1024)
+        pPtrRec = (QSPTRREC *)alloca(cbBuf);
+    else
+    {
+        pvFree = pPtrRec = (QSPTRREC *)_tmalloc(cbBuf);
+        if (pPtrRec)
+            return -ENOMEM;
+    }
+
+    /*
+     * Query the system state data.
+     */
+    int rc = DosQuerySysState(QS_PROCESS,
+                              0 /* no extra info */,
+                              iWho == RUSAGE_SELF ? fibGetPid() : 0 /* all processes*/,
+                              0 /* all threads */,
+                              pPtrRec,
+                              cbBuf);
+    if (rc)
+    {
+        free(pvFree);
+        return -__libc_back_native2errno(rc);
+    }
+
+    /*
+     * Digest the data.
+     */
+    uint32_t cTicksUser = 0;
+    uint32_t cTicksSystem = 0;
+    if (iWho == RUSAGE_SELF)
+    {
+        unsigned        iThread;
+        const unsigned  cThreads = pPtrRec->pProcRec->cTCB;
+        QSTREC         *paThreads = pPtrRec->pProcRec->pThrdRec;
+        for (iThread = 0; iThread < cThreads; iThread++)
+        {
+            cTicksUser += paThreads[iThread].usertime;
+            cTicksSystem += paThreads[iThread].systime;
+            /*LIBCLOG_MSG("thread %#x: RecType=%d tid=%d slot=%d sleepid=%#lx priority=%#lx systime=%ld usertime=%ld (%ld) state=%#x\n",
+                        iThread, paThreads[iThread].RecType, paThreads[iThread].tid, paThreads[iThread].slot, paThreads[iThread].sleepid,
+                        paThreads[iThread].priority, paThreads[iThread].systime, paThreads[iThread].usertime, paThreads[iThread].usertime * 32,
+                       paThreads[iThread].state);*/
+        }
+    }
+    else
+    {
+        /*
+         * We only consider immediate children because it's to
+         * expensive to do otherwise.
+         */
+        const pid_t ppid = fibGetPid();
+        QSPREC *pProcRec = pPtrRec->pProcRec;
+        while (pProcRec != NULL && pProcRec->RecType == QS_PROCESS)
+        {
+            /*LIBCLOG_MSG("process: RecType=%d pid=%d ppid=%d\n", pProcRec->RecType, pProcRec->pid, pProcRec->ppid); */
+            if (pProcRec->ppid == ppid)
+            {
+                unsigned        iThread;
+                const unsigned  cThreads = pProcRec->cTCB;
+                QSTREC         *paThreads = pProcRec->pThrdRec;
+                for (iThread = 0; iThread < cThreads; iThread++)
+                {
+                    cTicksUser += paThreads[iThread].usertime;
+                    cTicksSystem += paThreads[iThread].systime;
+                    /*LIBCLOG_MSG("thread %#x: RecType=%d tid=%d slot=%d sleepid=%#lx priority=%#lx systime=%ld usertime=%ld (%ld) state=%#x\n",
+                                iThread, paThreads[iThread].RecType, paThreads[iThread].tid, paThreads[iThread].slot, paThreads[iThread].sleepid,
+                                paThreads[iThread].priority, paThreads[iThread].systime, paThreads[iThread].usertime, paThreads[iThread].usertime * 32,
+                               paThreads[iThread].state);*/
+                }
+            }
+            /* next process */
+            pProcRec = (QSPREC *)&pProcRec->pThrdRec[pProcRec->cTCB];
+        }
+    }
+
+    /*
+     * Produce the output.
+     */
+    cTicksUser *= 32; /* make it milliseconds */
+    pUsage->ru_utime.tv_usec = (cTicksUser % 1000) * 1000;
+    pUsage->ru_utime.tv_sec  = cTicksUser / 1000;
+
+    cTicksSystem *= 32; /* make it milliseconds */
+    pUsage->ru_stime.tv_usec = (cTicksSystem % 1000) * 1000;
+    pUsage->ru_stime.tv_sec  = cTicksSystem / 1000;
+
+    /* we don't have this information. */
+    pUsage->ru_maxrss = -1;
+    pUsage->ru_ixrss = -1;
+    pUsage->ru_idrss = -1;
+    pUsage->ru_minflt = -1;
+    pUsage->ru_majflt = -1;
+    pUsage->ru_nswap = -1;
+    pUsage->ru_inblock = -1;
+    pUsage->ru_oublock = -1;
+    pUsage->ru_msgsnd = -1;
+    pUsage->ru_msgrcv = -1;
+    pUsage->ru_nsignals = -1;
+    pUsage->ru_nvcsw = -1;
+    pUsage->ru_nivcsw = -1;
+
+    free(pvFree);
+    return 0;
+}
+
+
+/**
+ * Get the resource usage of the process or the child processes.
+ *
+ * @returns 0 on success.
+ * @returns Neagted error code (errno.h) on failure.
+ * @param   iWho        Who to get the resource usage of, RUSAGE_SELF or RUSAGE_CHILDREN.
+ * @param   pUsage      Where to store the resource usage.
+ */
+int __libc_Back_processGetResourceUsage(int iWho, struct rusage *pUsage)
+{
+    LIBCLOG_ENTER("iWho=%d pUsage=%p\n", iWho, (void *)pUsage);
+    if (iWho != RUSAGE_SELF && iWho != RUSAGE_CHILDREN)
+        LIBCLOG_ERROR_RETURN_INT(-EINVAL);
+
+    /*
+     * Try query with increasing buffer sizes.
+     */
+    int rc;
+    if (iWho == RUSAGE_SELF)
+    {
+        static size_t volatile s_cbBufSelf = 512;
+        size_t cbBuf = s_cbBufSelf;
+        if (cbBuf > 64*1024)
+            s_cbBufSelf = cbBuf = 512;
+        while (cbBuf <= 64*1024 /* 64KB */)
+        {
+            rc = __libc_Back_processGetResourceUsageSub(iWho, pUsage, cbBuf);
+            if (rc != -E2BIG && rc != -EOVERFLOW)
+            {
+                s_cbBufSelf = cbBuf;
+                break;
+            }
+            cbBuf *= 2;
+            LIBCLOG_MSG("cbBufSelf *= 2 -> %zd\n", cbBuf);
+        }
+    }
+    else
+    {
+        static size_t volatile s_cbBufChildren = 8192;
+        size_t cbBuf = s_cbBufChildren;
+        if (cbBuf > 1024*1024)
+            s_cbBufChildren = cbBuf = 8192;
+        while (cbBuf <= 1024*1024 /* 1MB */)
+        {
+            rc = __libc_Back_processGetResourceUsageSub(iWho, pUsage, cbBuf);
+            if (rc != -E2BIG && rc != -EOVERFLOW)
+            {
+                s_cbBufChildren = cbBuf;
+                break;
+            }
+            cbBuf *= 2;
+            LIBCLOG_MSG("cbBufChildren *= 2 -> %zd\n", cbBuf);
+        }
+    }
+    LIBCLOG_MIX_RETURN_INT(rc);
+}
+
Index: /trunk/libc/src/kNIX/os2/b_threadSleep.c
===================================================================
--- /trunk/libc/src/kNIX/os2/b_threadSleep.c	(revision 2917)
+++ /trunk/libc/src/kNIX/os2/b_threadSleep.c	(revision 2918)
@@ -34,10 +34,9 @@
  *
  * @returns 0 on success.
- * @returns -EINVAL if the pReqTS is invalid.
  * @returns -EINTR if the interrupted by signal.
-
+ *
  * @param   u64NanoReq      Time to sleep, in nano seconds.
  * @param   pu64NanoRem     Where to store remaining time (also nano seconds).
-
+ *
  * @remark  For relativly small sleeps this api temporarily changes the thread
  *          priority to timecritical (that is, if it's in the normal or idle priority
Index: unk/libc/src/kNIX/os2/clock.c
===================================================================
--- /trunk/libc/src/kNIX/os2/clock.c	(revision 2917)
+++ 	(revision )
@@ -1,21 +1,0 @@
-/* sys/clock.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <os2emx.h>
-#include <time.h>
-#include <emx/syscalls.h>
-#include "syscalls.h"
-
-/* This function no longer tries to use QSV_TIME_LOW and QSV_TIME_HIGH
-   to increase the time before the return value wraps around.  Now, it
-   will wrap around after 49 days. */
-
-clock_t _STD(clock)(void)
-{
-    ULONG val_ms;
-    clock_t result;
-
-    _sys_get_clock(&val_ms);
-    result = (val_ms - _sys_clock0_ms) / 10;
-    return result;
-}
Index: unk/libc/src/kNIX/os2/core.c
===================================================================
--- /trunk/libc/src/kNIX/os2/core.c	(revision 2917)
+++ 	(revision )
@@ -1,12 +1,0 @@
-/* core.c (emx+gcc) -- Copyright (c) 1990-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <stdlib.h>
-#include <emx/syscalls.h>
-
-int _core (int handle)
-{
-  (void)handle;
-  /* Not implemented */
-  return -1;
-}
Index: unk/libc/src/kNIX/os2/execname.c
===================================================================
--- /trunk/libc/src/kNIX/os2/execname.c	(revision 2917)
+++ 	(revision )
@@ -1,30 +1,0 @@
-/* sys/execname.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#define INCL_DOS
-#define INCL_FSMACROS
-#include <os2emx.h>
-#include <stdlib.h>
-#include <string.h>
-#include <emx/syscalls.h>
-#include <klibc/fib.h>
-#include "syscalls.h"
-
-int _execname (char *dst, size_t size)
-{
-  ULONG rc;
-  FS_VAR();
-
-  if (size == 0)
-    return -1;
-
-  FS_SAVE_LOAD();
-  rc = DosQueryModuleName (fibGetExeHandle(), size, dst);
-  FS_RESTORE();
-  if (rc != 0)
-    {
-      *dst = 0;
-      return -1;
-    }
-  return 0;
-}
Index: unk/libc/src/kNIX/os2/filesys.c
===================================================================
--- /trunk/libc/src/kNIX/os2/filesys.c	(revision 2917)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/* sys/filesys.c (emx+gcc) -- Copyright (c) 1992-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <string.h>
-#include <stdlib.h>
-#include <errno.h>
-#define INCL_FSMACROS
-#include <os2emx.h>
-#include <alloca.h>
-#include <emx/syscalls.h>
-#include "syscalls.h"
-
-#define QFSA_SIZE 256
-
-int _filesys (const char *drive, char *name, size_t size)
-{
-  ULONG rc;
-  ULONG len;
-  FSQBUFFER2 *buf;
-  FS_VAR();
-
-  len = sizeof (FSQBUFFER2) + QFSA_SIZE;
-  buf = alloca (len);
-  FS_SAVE_LOAD();
-  rc = DosQueryFSAttach (drive, 1, FSAIL_QUERYNAME, buf, &len);
-  FS_RESTORE();
-  if (rc != 0)
-    {
-      _sys_set_errno (rc);
-      return -1;
-    }
-  if (buf->iType != FSAT_LOCALDRV && buf->iType != FSAT_REMOTEDRV)
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  if (buf->cbFSDName >= size)
-    {
-      errno = E2BIG;
-      return -1;
-    }
-  strcpy (name, buf->szFSDName + buf->cbName);
-  return 0;
-}
Index: unk/libc/src/kNIX/os2/getppid.c
===================================================================
--- /trunk/libc/src/kNIX/os2/getppid.c	(revision 2917)
+++ 	(revision )
@@ -1,11 +1,0 @@
-/* sys/getppid.c (emx+gcc) -- Copyright (c) 1992-1995 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#include <unistd.h>
-#include <os2emx.h>
-#include "syscalls.h"
-
-int _STD(getppid) (void)
-{
-  return _sys_ppid;
-}
Index: unk/libc/src/kNIX/os2/sleep2.c
===================================================================
--- /trunk/libc/src/kNIX/os2/sleep2.c	(revision 2917)
+++ 	(revision )
@@ -1,19 +1,0 @@
-/* sys/sleep2.c (emx+gcc) -- Copyright (c) 1993-1996 by Eberhard Mattes */
-
-#include "libc-alias.h"
-#define INCL_DOSPROCESS
-#define INCL_FSMACROS
-#include <os2emx.h>
-#include <stdlib.h>
-#include <emx/syscalls.h>
-#include "syscalls.h"
-
-unsigned _sleep2 (unsigned millisec)
-{
-  FS_VAR();
-
-  FS_SAVE_LOAD();
-  DosSleep (millisec);
-  FS_RESTORE();
-  return 0;
-}
Index: unk/libc/src/kNIX/os2/uflags.c
===================================================================
--- /trunk/libc/src/kNIX/os2/uflags.c	(revision 2917)
+++ 	(revision )
@@ -1,14 +1,0 @@
-/* sys/uflags.c (emx+gcc) -- Copyright (c) 1996 by Eberhard Mattes */
-
-#include "kNIX.h"
-#include <sys/uflags.h>
-#include "syscalls.h"
-
-int _uflags (int mask, int new_flags)
-{
-  int ret;
-
-  ret = _sys_uflags;
-  _sys_uflags = (_sys_uflags & ~mask) | (new_flags & mask);
-  return ret;
-}
Index: /trunk/libc/src/libc/io/Makefile.kmk
===================================================================
--- /trunk/libc/src/libc/io/Makefile.kmk	(revision 2917)
+++ /trunk/libc/src/libc/io/Makefile.kmk	(revision 2918)
@@ -142,4 +142,5 @@
     $(PATH_LIBC_SRC)/libc/io/_crlf.c \
     $(PATH_LIBC_SRC)/libc/io/_fbuf.c \
+    $(PATH_LIBC_SRC)/libc/io/_filesys.c \
     $(PATH_LIBC_SRC)/libc/io/_fill.c \
     $(PATH_LIBC_SRC)/libc/io/_flush.c \
Index: /trunk/libc/src/libc/io/_filesys.c
===================================================================
--- /trunk/libc/src/libc/io/_filesys.c	(revision 2918)
+++ /trunk/libc/src/libc/io/_filesys.c	(revision 2918)
@@ -0,0 +1,64 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - _filesys().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_FS
+#include <klibc/logstrict.h>
+
+/**
+ * Queries the file system name.
+ *
+ * @returns 0 on success.
+ * @returns -1 and errno on failure. If the buffer is too small, errno is set to EOVERFLOW.
+ *
+ * @param   pszMountpoint   The mount point of the file system. (Will actually work for non-mountpoints too.)
+ * @param   pszNameBuf      Where to store the file system name.
+ * @param   cchNameBuf      The size of the buffer.
+ */
+int _filesys(const char *pszMountpoint, char *pszNameBuf, size_t cchNameBuf)
+{
+    LIBCLOG_ENTER("pszMountpoint=%p:{%s} pszNameBuf=%p cchNamebuf=%zd\n", (void *)pszMountpoint, pszMountpoint, (void *)pszNameBuf, cchNameBuf);
+    struct statfs StatFS;
+    int rc = statfs(pszMountpoint, &StatFS);
+    if (!rc)
+    {
+        const size_t cch = strlen(StatFS.f_fstypename);
+        if (cch >= cchNameBuf)
+        {
+            errno = EOVERFLOW;
+            LIBCLOG_ERROR_RETURN_INT(-1);
+        }
+        memcpy(pszNameBuf, StatFS.f_fstypename, cch + 1);
+        LIBCLOG_RETURN_MSG(rc, "ret %d - pszNameBuf=%p:{%s}\n", rc, (void *)pszNameBuf, pszNameBuf);
+    }
+    LIBCLOG_ERROR_RETURN_INT(rc);
+}
+
Index: /trunk/libc/src/libc/process/Makefile.kmk
===================================================================
--- /trunk/libc/src/libc/process/Makefile.kmk	(revision 2917)
+++ /trunk/libc/src/libc/process/Makefile.kmk	(revision 2918)
@@ -35,4 +35,5 @@
 libc_libc_process_SOURCES = \
     $(PATH_LIBC_SRC)/libc/process/bsd_signal.c \
+    $(PATH_LIBC_SRC)/libc/process/clock.c \
     $(PATH_LIBC_SRC)/libc/process/execl.c \
     $(PATH_LIBC_SRC)/libc/process/execle.c \
@@ -47,5 +48,7 @@
     $(PATH_LIBC_SRC)/libc/process/getitimer.c \
     $(PATH_LIBC_SRC)/libc/process/getrlimit.c \
+    $(PATH_LIBC_SRC)/libc/process/getrusage.c \
     $(PATH_LIBC_SRC)/libc/process/getpid.c \
+    $(PATH_LIBC_SRC)/libc/process/getppid.c \
     $(PATH_LIBC_SRC)/libc/process/getpriority.c \
     $(PATH_LIBC_SRC)/libc/process/kill.c \
@@ -92,4 +95,5 @@
     $(PATH_LIBC_SRC)/libc/process/sigwait.c \
     $(PATH_LIBC_SRC)/libc/process/sigwaitinfo.c \
+    $(PATH_LIBC_SRC)/libc/process/sleep.c \
     $(PATH_LIBC_SRC)/libc/process/spawnl.c \
     $(PATH_LIBC_SRC)/libc/process/spawnle.c \
@@ -112,7 +116,9 @@
     $(PATH_LIBC_SRC)/libc/process/waitpid.c \
     $(PATH_LIBC_SRC)/libc/process/_atfork_callback.c \
+    $(PATH_LIBC_SRC)/libc/process/_execname.c \
     $(PATH_LIBC_SRC)/libc/process/_gettid.c \
     $(PATH_LIBC_SRC)/libc/process/_signal_os2.c \
     $(PATH_LIBC_SRC)/libc/process/_signal_sysv.c \
+    $(PATH_LIBC_SRC)/libc/process/_sleep2.c \
 
 libc_libc_process_SOURCES.os2 = \
Index: /trunk/libc/src/libc/process/_execname.c
===================================================================
--- /trunk/libc/src/libc/process/_execname.c	(revision 2918)
+++ /trunk/libc/src/libc/process/_execname.c	(revision 2918)
@@ -0,0 +1,40 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - _execname().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <stdlib.h>
+#include <klibc/backend.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_LDR
+#include <klibc/logstrict.h>
+
+int _execname(char *pszNameBuf, size_t cchNameBuf)
+{
+    LIBCLOG_ENTER("pszNameBuf=%p cchNameBuf=%zd\n", (void *)pszNameBuf, cchNameBuf);
+    int rc = __libc_Back_ldrExeName(pszNameBuf, cchNameBuf);
+    if (!rc)
+        LIBCLOG_RETURN_MSG(0, "ret %d - pszNameBuf=%p:{%s}\n", rc, (void *)pszNameBuf, pszNameBuf);
+    LIBCLOG_ERROR_RETURN_INT(-1);
+}
Index: /trunk/libc/src/libc/process/_sleep2.c
===================================================================
--- /trunk/libc/src/libc/process/_sleep2.c	(revision 2918)
+++ /trunk/libc/src/libc/process/_sleep2.c	(revision 2918)
@@ -0,0 +1,40 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - _sleep2().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <stdlib.h>
+#include <klibc/backend.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
+#include <klibc/logstrict.h>
+
+unsigned _sleep2(unsigned cMillies)
+{
+    uint64_t cNanoRem = 0;
+    int rc = __libc_Back_threadSleep(cMillies * UINT64_C(1000000), &cNanoRem);
+    if (!rc)
+        return 0;
+    return cNanoRem / 1000000;
+}
Index: /trunk/libc/src/libc/process/clock.c
===================================================================
--- /trunk/libc/src/libc/process/clock.c	(revision 2918)
+++ /trunk/libc/src/libc/process/clock.c	(revision 2918)
@@ -0,0 +1,51 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - clock().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+#include "libc-alias.h"
+#include <time.h>
+#include <klibc/backend.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME
+#include <klibc/logstrict.h>
+
+clock_t _STD(clock)(void)
+{
+    LIBCLOG_ENTER("\n");
+
+    /* Get the times. */
+    struct rusage Usage;
+    int rc = __libc_Back_processGetResourceUsage(RUSAGE_SELF, &Usage);
+    if (__predict_false(rc != 0))
+    {
+        LIBC_ASSERTM_FAILED("rc=%d\n", rc);
+        LIBCLOG_ERROR_RETURN_INT(-1);
+    }
+
+    /* Sum and convert to clock ticks. */
+    uint64_t cMicroSeconds = ((uint64_t)Usage.ru_stime.tv_sec + (uint64_t)Usage.ru_utime.tv_sec) * 1000000
+                           +            Usage.ru_stime.tv_usec +          Usage.ru_utime.tv_usec;
+    clock_t cTicks = cMicroSeconds / (1000000 / CLOCKS_PER_SEC);
+    LIBCLOG_RETURN_MSG(cTicks, "ret %llu (%#llx)\n", (long long)cTicks, (long long)cTicks);
+}
+
Index: /trunk/libc/src/libc/process/getpid.c
===================================================================
--- /trunk/libc/src/libc/process/getpid.c	(revision 2917)
+++ /trunk/libc/src/libc/process/getpid.c	(revision 2918)
@@ -2,5 +2,5 @@
 /** @file
  *
- * LIBC - getpid().
+ * kLIBC - getpid().
  *
  * Copyright (c) 2006 knut st. osmundsen <bird@innotek.de>
@@ -25,13 +25,8 @@
  */
 
-
-/*******************************************************************************
-*   Header Files                                                               *
-*******************************************************************************/
 #include "libc-alias.h"
 #include <unistd.h>
 #include <process.h>
 #include <klibc/fib.h>
-
 
 /**
@@ -40,5 +35,5 @@
  * @returns process id.
  */
-int _STD(getpid)(void)
+pid_t _STD(getpid)(void)
 {
     return fibGetPid();
Index: /trunk/libc/src/libc/process/getppid.c
===================================================================
--- /trunk/libc/src/libc/process/getppid.c	(revision 2918)
+++ /trunk/libc/src/libc/process/getppid.c	(revision 2918)
@@ -0,0 +1,44 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - getppid().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <unistd.h>
+#include <klibc/fib.h>
+
+/**
+ * Get the parent process id.
+ *
+ * @returns The parent process id.
+ */
+pid_t _STD(getppid)(void)
+{
+#ifdef fibGetPPid
+    return fibGetPPid();
+#else
+    return __libc_Back_processParentId();
+#endif
+}
+
Index: /trunk/libc/src/libc/process/getrusage.c
===================================================================
--- /trunk/libc/src/libc/process/getrusage.c	(revision 2918)
+++ /trunk/libc/src/libc/process/getrusage.c	(revision 2918)
@@ -0,0 +1,43 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - getrusage().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <sys/resource.h>
+#include <errno.h>
+#include <klibc/backend.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
+#include <klibc/logstrict.h>
+
+int _STD(getrusage)(int iWho, struct rusage *pUsage)
+{
+    LIBCLOG_ENTER("iWho=%d pUsage=%p\n", iWho, (void *)pUsage);
+    int rc = __libc_Back_processGetResourceUsage(iWho, pUsage);
+    if (!rc)
+        LIBCLOG_RETURN_INT(rc);
+    errno = -rc;
+    LIBCLOG_ERROR_RETURN_INT(-1);
+}
+
Index: /trunk/libc/src/libc/process/siginterrupt_data.c
===================================================================
--- /trunk/libc/src/libc/process/siginterrupt_data.c	(revision 2917)
+++ /trunk/libc/src/libc/process/siginterrupt_data.c	(revision 2918)
@@ -29,5 +29,5 @@
 *******************************************************************************/
 #include "libc-alias.h"
-#include <InnoTekLIBC/libc.h>
+#include <sys/signal.h>
 
 
Index: /trunk/libc/src/libc/process/sleep.c
===================================================================
--- /trunk/libc/src/libc/process/sleep.c	(revision 2918)
+++ /trunk/libc/src/libc/process/sleep.c	(revision 2918)
@@ -0,0 +1,41 @@
+/* $Id: $ */
+/** @file
+ *
+ * kLIBC - sleep().
+ *
+ * Copyright (c) 2006 knut st. osmundsen <bird-srcspam@anduin.net>
+ *
+ *
+ * This file is part of kLIBC.
+ *
+ * kLIBC 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.
+ *
+ * kLIBC 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 kLIBC; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+
+#include "libc-alias.h"
+#include <stdlib.h>
+#include <klibc/backend.h>
+#define __LIBC_LOG_GROUP __LIBC_LOG_GRP_PROCESS
+#include <klibc/logstrict.h>
+
+unsigned sleep(unsigned cSeconds)
+{
+    uint64_t cNanoRem = 0;
+    int rc = __libc_Back_threadSleep(cSeconds * UINT64_C(1000000000), &cNanoRem);
+    if (!rc)
+        return 0;
+    return cNanoRem / 1000000000;
+}
+
Index: /trunk/libc/src/libc/time/times.c
===================================================================
--- /trunk/libc/src/libc/time/times.c	(revision 2917)
+++ /trunk/libc/src/libc/time/times.c	(revision 2918)
@@ -4,5 +4,4 @@
  * kLIBC - times().
  *
- * Copyright (c) 1990-1996 by Eberhard Mattes
  * Copyright (c) 2004-2006 knut st. osmundsen <bird-srcspam@anduin.net>
  *
@@ -27,10 +26,18 @@
 
 #include "libc-alias.h"
+#include <sys/times.h>
+#include <sys/time.h>
 #include <time.h>
-#include <sys/time.h>
-#include <sys/times.h>
+#include <errno.h>
+#include <klibc/backend.h>
 #define __LIBC_LOG_GROUP __LIBC_LOG_GRP_TIME
 #include <klibc/logstrict.h>
 
+/** Converts a time value to clock ticks. */
+static clock_t tv2ticks(struct timeval const *ptv)
+{
+    return ptv->tv_sec * (uint64_t)CLOCKS_PER_SEC
+         + ptv->tv_usec * (uint64_t)(1000000 / CLOCKS_PER_SEC);
+}
 
 /**
@@ -38,22 +45,48 @@
  * @remark return value overflows
  */
-clock_t _STD(times)(struct tms *buffer)
+clock_t _STD(times)(struct tms *pBuf)
 {
-    LIBCLOG_ENTER("buffer=%p\n", (void *)buffer);
+    LIBCLOG_ENTER("pBuf=%p\n", (void *)pBuf);
+
+    /*
+     * Get sys/user times if requested.
+     */
+    if (pBuf)
+    {
+        struct rusage Usage;
+        int rc = __libc_Back_processGetResourceUsage(RUSAGE_SELF, &Usage);
+        if (!rc)
+        {
+            pBuf->tms_utime = tv2ticks(&Usage.ru_utime);
+            pBuf->tms_stime = tv2ticks(&Usage.ru_stime);
+            rc = __libc_Back_processGetResourceUsage(RUSAGE_CHILDREN, &Usage);
+            if (!rc)
+            {
+                pBuf->tms_cutime = tv2ticks(&Usage.ru_utime);
+                pBuf->tms_cstime = tv2ticks(&Usage.ru_stime);
+            }
+        }
+        if (rc)
+        {
+            errno = -rc;
+            LIBCLOG_ERROR_RETURN_INT(-1);
+        }
+    }
+
+    /*
+     * Get monotone time and recalc it to ticks.
+     */
+    /** @todo this should be a monotone time source. gettimeofday() isn't monotone. */
     struct timeval tv;
-    if (buffer)
-    {
-        buffer->tms_utime = clock();  /* clock () * HZ / CLOCKS_PER_SEC */
-        buffer->tms_stime = 0;
-        buffer->tms_cutime = 0;
-        buffer->tms_cstime = 0;
-    }
     if (gettimeofday(&tv, NULL) != 0)
         LIBCLOG_ERROR_RETURN_INT(-1);
-    clock_t rc = CLK_TCK * tv.tv_sec + (CLK_TCK * tv.tv_usec) / 1000000;
-    if (buffer)
-        LIBCLOG_RETURN_MSG(rc, "ret %d (%#x) - buffer={.tms_utime=%d, .tms_stime=%d, .tms_cutime=%d, .tms_cstime=%d}\n",
-                           (int)rc, (int)rc, (int)buffer->tms_utime, (int)buffer->tms_stime, (int)buffer->tms_cutime,
-                           (int)buffer->tms_cstime);
-    LIBCLOG_RETURN_MSG(rc, "ret %d (%#x)\n", (int)rc, (int)rc);
+    clock_t cTicks = tv2ticks(&tv);
+
+    if (pBuf)
+        LIBCLOG_RETURN_MSG(cTicks, "ret %lld (%#llx) - pBuf={.tms_utime=%lld, .tms_stime=%lld, .tms_cutime=%lld, .tms_cstime=%lld}\n",
+                           (long long)cTicks, (long long)cTicks,
+                           (long long)pBuf->tms_utime, (long long)pBuf->tms_stime,
+                           (long long)pBuf->tms_cutime, (long long)pBuf->tms_cstime);
+    LIBCLOG_RETURN_MSG(cTicks, "ret %lld (%#llx)\n", (long long)cTicks, (long long)cTicks);
 }
+
