[haiku-commits] haiku: hrev43317 - in src/system/libroot/posix: . unistd stdlib stdio sys

  • From: zooey@xxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 24 Nov 2011 23:50:07 +0100 (CET)

hrev43317 adds 4 changesets to branch 'master'
old head: 6fabf01910f42c9fd2aaf4e739b5c2abe5ddbd48
new head: 8fd51c08197d5acd9ff3c63aaed4772512bb8310

----------------------------------------------------------------------------

1f84898: Let ErrnoMaintainer restore errno unconditionally.
  
  * we never want to let ICU calls change the errno at all, so we always
    restore it to the value it had before entering ICU (not just if it
    was 0)

ae90193: Introduce __set_errno() throughout libroot.
  
  * add errno_private.h, which defines the __set_errno() macro with
    and without tracing
  * instead of setting errno manually, all libroot's code now invokes
    __set_errno(), which makes it much easier to trace changes to errno
  * redirect glibc's use of __set_errno() to our own version

59e43b2: Add tracing to some locale backend functions.

8fd51c0: Use ErrnoMaintainer in setlocale() to protect errno.
  
  * this avoids spurious errno changes leaking into application code,
    which could become confused - i.e. 'rm' on a gcc4 build would always
    prompt for confirmation
  
  I spend a couple of hours hunting down the behavioural difference
  between gcc2- and gcc4-builds and it turns out that the reason for that
  is that gcc4's libstdc++-code initializes its own locale data via the
  POSIX calls, which trigger (correct) errno value changes, which were the
  ones leaking into application code.

                                    [ Oliver Tappe <zooey@xxxxxxxxxxxxxxx> ]


----------------------------------------------------------------------------

153 files changed, 571 insertions(+), 305 deletions(-)
headers/private/libroot/ErrnoMaintainer.h          |    4 +-
headers/private/libroot/errno_private.h            |   28 ++++++
src/libs/stdc++/legacy/Jamfile                     |    2 +
src/system/libroot/add-ons/icu/ICUCtypeData.cpp    |   25 +++++-
src/system/libroot/os/arch/x86/compatibility.c     |    7 +-
src/system/libroot/os/find_directory.cpp           |    3 +-
src/system/libroot/os/fs_attr.cpp                  |    3 +-
src/system/libroot/os/fs_index.c                   |    3 +-
src/system/libroot/os/fs_info.c                    |    5 +-
src/system/libroot/os/fs_query.cpp                 |    7 +-
src/system/libroot/os/time.cpp                     |    1 +
src/system/libroot/posix/dirent.c                  |   15 ++--
src/system/libroot/posix/fcntl.cpp                 |    1 +
src/system/libroot/posix/glibc/arch/m68k/Jamfile   |    2 +
src/system/libroot/posix/glibc/arch/ppc/Jamfile    |    2 +
src/system/libroot/posix/glibc/arch/x86/Jamfile    |    2 +
src/system/libroot/posix/glibc/iconv/Jamfile       |    3 +
.../libroot/posix/glibc/include/bits/errno.h       |    2 +-
src/system/libroot/posix/glibc/libio/Jamfile       |    2 +
src/system/libroot/posix/glibc/libio/fileops.c     |    6 --
src/system/libroot/posix/glibc/libio/ioseekoff.c   |    6 --
src/system/libroot/posix/glibc/libio/libioP.h      |    3 -
src/system/libroot/posix/glibc/libio/oldfileops.c  |    6 --
src/system/libroot/posix/glibc/misc/Jamfile        |    3 +
.../libroot/posix/glibc/stdio-common/Jamfile       |    3 +-
.../libroot/posix/glibc/stdio-common/tempname.c    |    3 -
.../libroot/posix/glibc/stdio-common/vfscanf.c     |    4 +-
src/system/libroot/posix/glibc/stdlib/Jamfile      |    2 +
src/system/libroot/posix/glibc/stdlib/strtol.c     |    8 +--
src/system/libroot/posix/glibc/wcsmbs/Jamfile      |    3 +
src/system/libroot/posix/glob.c                    |   16 ++--
src/system/libroot/posix/grp.cpp                   |    7 +-
src/system/libroot/posix/locale/Jamfile            |    1 +
src/system/libroot/posix/locale/setlocale.cpp      |    4 +
src/system/libroot/posix/locale/wctype.cpp         |    6 +-
src/system/libroot/posix/malloc/wrapper.cpp        |   11 ++-
src/system/libroot/posix/malloc_debug/Jamfile      |    2 +-
src/system/libroot/posix/malloc_debug/heap.cpp     |    1 +
src/system/libroot/posix/poll.c                    |    1 +
src/system/libroot/posix/pwd.cpp                   |    7 +-
src/system/libroot/posix/pwd_query.c               |   70 ++++++++--------
src/system/libroot/posix/scheduler.cpp             |    5 +-
src/system/libroot/posix/semaphore.cpp             |    7 +-
src/system/libroot/posix/shadow.cpp                |   11 ++-
src/system/libroot/posix/signal/kill.c             |    5 +-
src/system/libroot/posix/signal/killpg.cpp         |    4 +-
.../libroot/posix/signal/set_signal_mask.cpp       |    1 +
src/system/libroot/posix/signal/set_signal_stack.c |    3 +-
src/system/libroot/posix/signal/sigaction.cpp      |    1 +
src/system/libroot/posix/signal/sigaltstack.c      |    3 +-
src/system/libroot/posix/signal/signal.cpp         |    3 +-
src/system/libroot/posix/signal/sigpending.cpp     |    1 +
src/system/libroot/posix/signal/sigqueue.cpp       |    1 +
.../libroot/posix/signal/sigset_accessors.cpp      |   13 ++--
src/system/libroot/posix/signal/sigsuspend.cpp     |    3 +-
src/system/libroot/posix/signal/sigtimedwait.cpp   |    1 +
src/system/libroot/posix/signal/strsignal.cpp      |    1 +
src/system/libroot/posix/stdio/fclose.c            |    5 +-
src/system/libroot/posix/stdio/fflush.c            |    5 +-
src/system/libroot/posix/stdio/findfp.c            |    4 +-
src/system/libroot/posix/stdio/flags.c             |    5 +-
src/system/libroot/posix/stdio/fopen.c             |    4 +-
src/system/libroot/posix/stdio/fputc.c             |    5 +-
src/system/libroot/posix/stdio/fseek.c             |    7 +-
src/system/libroot/posix/stdio/fvwrite.c           |    5 +-
src/system/libroot/posix/stdio/fwalk.c             |    3 +
src/system/libroot/posix/stdio/putc.c              |    5 +-
src/system/libroot/posix/stdio/refill.c            |    5 +-
src/system/libroot/posix/stdio/remove.c            |    3 +-
src/system/libroot/posix/stdio/rename.c            |    3 +-
src/system/libroot/posix/stdio/rewind.c            |    4 +-
src/system/libroot/posix/stdio/vfprintf.c          |   26 +++---
src/system/libroot/posix/stdio/wbuf.c              |    5 +-
src/system/libroot/posix/stdlib/atfork.c           |    6 +-
src/system/libroot/posix/stdlib/env.cpp            |   11 ++-
src/system/libroot/posix/stdlib/heapsort.c         |    4 +-
src/system/libroot/posix/stdlib/merge.c            |    4 +-
src/system/libroot/posix/stdlib/mktemp.c           |    8 +-
src/system/libroot/posix/stdlib/radixsort.c        |    6 +-
src/system/libroot/posix/stdlib/realpath.cpp       |    3 +-
src/system/libroot/posix/stdlib/strfmon.c          |    8 +-
src/system/libroot/posix/stdlib/strtod.c           |    6 +-
src/system/libroot/posix/stdlib/strtol.c           |    6 +-
src/system/libroot/posix/stdlib/strtoll.c          |    6 +-
src/system/libroot/posix/stdlib/strtoq.c           |    7 +-
src/system/libroot/posix/stdlib/strtoul.c          |    6 +-
src/system/libroot/posix/stdlib/strtoull.c         |    6 +-
src/system/libroot/posix/stdlib/strtouq.c          |    7 +-
src/system/libroot/posix/string/Jamfile            |    5 +-
src/system/libroot/posix/string/strcoll.cpp        |    3 +-
src/system/libroot/posix/string/strxfrm.cpp        |    3 +-
src/system/libroot/posix/sys/chmod.c               |    1 +
src/system/libroot/posix/sys/flock.c               |    3 +-
src/system/libroot/posix/sys/getrusage.c           |    4 +-
src/system/libroot/posix/sys/itimer.cpp            |    1 +
src/system/libroot/posix/sys/mkdir.c               |    1 +
src/system/libroot/posix/sys/mkfifo.c              |    1 +
src/system/libroot/posix/sys/mman.cpp              |    9 +-
src/system/libroot/posix/sys/rlimit.c              |    4 +-
[ *** stats truncated: 54 lines dropped *** ]

############################################################################

Commit:      1f848981901657d61e01538505982c5c71a32494
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1f84898
Author:      Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
Date:        Thu Nov 24 22:27:59 2011 UTC

Let ErrnoMaintainer restore errno unconditionally.

* we never want to let ICU calls change the errno at all, so we always
  restore it to the value it had before entering ICU (not just if it
  was 0)

----------------------------------------------------------------------------

diff --git a/headers/private/libroot/ErrnoMaintainer.h 
b/headers/private/libroot/ErrnoMaintainer.h
index c01f3d9..f0de2bc 100644
--- a/headers/private/libroot/ErrnoMaintainer.h
+++ b/headers/private/libroot/ErrnoMaintainer.h
@@ -25,9 +25,9 @@ public:
 
        ~ErrnoMaintainer()
        {
-               if (errno != 0 && fErrnoUponEntry == 0)
-                       errno = 0;
+               errno = fErrnoUponEntry;
        }
+
 private:
        int fErrnoUponEntry;
 };

############################################################################

Commit:      ae9019359606f1db67632ef51a77ce70001d3770
URL:         http://cgit.haiku-os.org/haiku/commit/?id=ae90193
Author:      Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
Date:        Thu Nov 24 22:40:10 2011 UTC

Introduce __set_errno() throughout libroot.

* add errno_private.h, which defines the __set_errno() macro with
  and without tracing
* instead of setting errno manually, all libroot's code now invokes
  __set_errno(), which makes it much easier to trace changes to errno
* redirect glibc's use of __set_errno() to our own version

----------------------------------------------------------------------------

diff --git a/headers/private/libroot/errno_private.h 
b/headers/private/libroot/errno_private.h
new file mode 100644
index 0000000..eb776e1
--- /dev/null
+++ b/headers/private/libroot/errno_private.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2011, Oliver Tappe, zooey@xxxxxxxxxxxxxxxx
+ * Distributed under the terms of the MIT License.
+ */
+#ifndef _ERRNO_PRIVATE_H
+#define _ERRNO_PRIVATE_H
+
+
+#include <errno.h>
+
+//#define TRACE_ERRNO
+
+#if defined(TRACE_ERRNO) && !defined(_KERNEL_MODE)
+#      include <OS.h>
+#      define __set_errno(x)                                                   
                                                  \
+               do {                                                            
                                                                  \
+                       int error = (x);                                        
                                                          \
+                       debug_printf("%s:%d - setting errno to %x\n", __FILE__, 
__LINE__, \
+                               error);                                         
                                                                  \
+                       errno = error;                                          
                                                          \
+               } while (0)
+#else
+#      define __set_errno(x) \
+               do { errno = (x); } while (0)
+#endif
+
+
+#endif // _ERRNO_PRIVATE_H
diff --git a/src/libs/stdc++/legacy/Jamfile b/src/libs/stdc++/legacy/Jamfile
index 2db2e5e..516d688 100644
--- a/src/libs/stdc++/legacy/Jamfile
+++ b/src/libs/stdc++/legacy/Jamfile
@@ -25,6 +25,8 @@ SYSHDRS =
        [ FDirName $(HAIKU_TOP) headers os support ] 
        $(TARGET_GCC_HEADERS_DIR) ;             # such that include_next will 
work
 
+UsePrivateHeaders libroot ;
+
 # some source-files generate several different objects, depending on
 # the defines that are used during the compilation call.
 # So we explicitly state each of these (with their respective defines):
diff --git a/src/system/libroot/os/arch/x86/compatibility.c 
b/src/system/libroot/os/arch/x86/compatibility.c
index 9e47b55..6ba9fec 100644
--- a/src/system/libroot/os/arch/x86/compatibility.c
+++ b/src/system/libroot/os/arch/x86/compatibility.c
@@ -10,6 +10,7 @@
 #include <sys/stat.h>
 
 #include <SupportDefs.h>
+#include <errno_private.h>
 #include <fs_info.h>
 #include <fs_volume.h>
 
@@ -116,13 +117,13 @@ mount(const char *filesystem, const char *where, const 
char *device, ulong flags
 
        // we don't support passing (binary) parameters
        if (parms != NULL || len != 0 || flags & ~1) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return -1;
        }
 
        err = fs_mount_volume(where, device, filesystem, mountFlags, NULL);
        if (err < B_OK) {
-               errno = err;
+               __set_errno(err);
                return -1;
        }
        return 0;
@@ -136,7 +137,7 @@ unmount(const char *path)
 
        err = fs_unmount_volume(path, 0);
        if (err < B_OK) {
-               errno = err;
+               __set_errno(err);
                return -1;
        }
        return 0;
diff --git a/src/system/libroot/os/find_directory.cpp 
b/src/system/libroot/os/find_directory.cpp
index a324dc8..830beb5 100644
--- a/src/system/libroot/os/find_directory.cpp
+++ b/src/system/libroot/os/find_directory.cpp
@@ -24,6 +24,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <errno_private.h>
 #include <user_group.h>
 
 /* use pwents to find home */
@@ -129,7 +130,7 @@ create_path(const char *path, mode_t mode)
 
                strlcpy(buffer, path, i + 1);
                if (stat(buffer, &st) < 0) {
-                       errno = 0;
+                       __set_errno(0);
                        if (mkdir(buffer, mode) < 0)
                                return errno;
                }
diff --git a/src/system/libroot/os/fs_attr.cpp 
b/src/system/libroot/os/fs_attr.cpp
index 7e90606..fecfdd0 100644
--- a/src/system/libroot/os/fs_attr.cpp
+++ b/src/system/libroot/os/fs_attr.cpp
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 
 #include <dirent_private.h>
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
@@ -27,7 +28,7 @@ open_attr_dir(int file, const char *path, bool traverse)
 
        int fd = _kern_open_attr_dir(file, path, traverse);
        if (fd < 0) {
-               errno = fd;
+               __set_errno(fd);
                return NULL;
        }
 
diff --git a/src/system/libroot/os/fs_index.c b/src/system/libroot/os/fs_index.c
index 2fe30cc..89469e2 100644
--- a/src/system/libroot/os/fs_index.c
+++ b/src/system/libroot/os/fs_index.c
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 
 #include <dirent_private.h>
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
@@ -60,7 +61,7 @@ fs_open_index_dir(dev_t device)
 
        int fd = _kern_open_index_dir(device);
        if (fd < 0) {
-               errno = fd;
+               __set_errno(fd);
                return NULL;
        }
 
diff --git a/src/system/libroot/os/fs_info.c b/src/system/libroot/os/fs_info.c
index eda4b1b..d9bb11d 100644
--- a/src/system/libroot/os/fs_info.c
+++ b/src/system/libroot/os/fs_info.c
@@ -1,4 +1,4 @@
-/* 
+/*
 ** Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
 ** Distributed under the terms of the Haiku License.
 */
@@ -10,13 +10,14 @@
 #include <fcntl.h>
 #include <errno.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
 #define RETURN_AND_SET_ERRNO(status) \
        { \
                if (status < 0) { \
-                       errno = status; \
+                       __set_errno(status); \
                        return -1; \
                } \
                return status; \
diff --git a/src/system/libroot/os/fs_query.cpp 
b/src/system/libroot/os/fs_query.cpp
index 781ae67..3feac44 100644
--- a/src/system/libroot/os/fs_query.cpp
+++ b/src/system/libroot/os/fs_query.cpp
@@ -13,6 +13,7 @@
 #include <string.h>
 
 #include <dirent_private.h>
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
@@ -22,14 +23,14 @@ open_query_etc(dev_t device, const char *query,
        uint32 flags, port_id port, int32 token)
 {
        if (device < 0 || query == NULL || query[0] == '\0') {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return NULL;
        }
 
        // open
        int fd = _kern_open_query(device, query, strlen(query), flags, port, 
token);
        if (fd < 0) {
-               errno = fd;
+               __set_errno(fd);
                return NULL;
        }
 
@@ -57,7 +58,7 @@ fs_open_live_query(dev_t device, const char *query,
 {
        // check parameters
        if (port < 0) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return NULL;
        }
 
diff --git a/src/system/libroot/os/time.cpp b/src/system/libroot/os/time.cpp
index 3c8810f..19d2953 100644
--- a/src/system/libroot/os/time.cpp
+++ b/src/system/libroot/os/time.cpp
@@ -13,6 +13,7 @@
 #include <OS.h>
 
 #include <commpage_defs.h>
+#include <errno_private.h>
 #include <libroot_private.h>
 #include <real_time_data.h>
 #include <user_timer_defs.h>
diff --git a/src/system/libroot/posix/dirent.c 
b/src/system/libroot/posix/dirent.c
index fef3e3b..09f5f5f 100644
--- a/src/system/libroot/posix/dirent.c
+++ b/src/system/libroot/posix/dirent.c
@@ -13,6 +13,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
@@ -41,7 +42,7 @@ do_seek_dir(DIR* dir)
        if (dir->seek_position < dir->current_position) {
                status_t status = _kern_rewind_dir(dir->fd);
                if (status < 0) {
-                       errno = status;
+                       __set_errno(status);
                        return -1;
                }
 
@@ -81,7 +82,7 @@ do_seek_dir(DIR* dir)
                        (char*)dir + DIR_BUFFER_SIZE - 
(char*)&dir->first_entry, USHRT_MAX);
                if (count <= 0) {
                        if (count < 0)
-                               errno = count;
+                               __set_errno(count);
 
                        // end of directory
                        return -1;
@@ -105,7 +106,7 @@ __create_dir_struct(int fd)
 
        DIR* dir = (DIR*)malloc(DIR_BUFFER_SIZE);
        if (dir == NULL) {
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                return NULL;
        }
 
@@ -130,7 +131,7 @@ fdopendir(int fd)
        // descriptors, we have to open a fresh one explicitly.
        int dirFD = _kern_open_dir(fd, NULL);
        if (dirFD < 0) {
-               errno = dirFD;
+               __set_errno(dirFD);
                return NULL;
        }
 
@@ -164,7 +165,7 @@ opendir(const char* path)
 
        int fd = _kern_open_dir(-1, path);
        if (fd < 0) {
-               errno = fd;
+               __set_errno(fd);
                return NULL;
        }
 
@@ -184,7 +185,7 @@ closedir(DIR* dir)
        int status;
 
        if (dir == NULL) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return -1;
        }
 
@@ -224,7 +225,7 @@ readdir(DIR* dir)
                (char*)dir + DIR_BUFFER_SIZE - (char*)&dir->first_entry, 
USHRT_MAX);
        if (count <= 0) {
                if (count < 0)
-                       errno = count;
+                       __set_errno(count);
 
                // end of directory
                return NULL;
diff --git a/src/system/libroot/posix/fcntl.cpp 
b/src/system/libroot/posix/fcntl.cpp
index 1e0608b..2f99596 100644
--- a/src/system/libroot/posix/fcntl.cpp
+++ b/src/system/libroot/posix/fcntl.cpp
@@ -13,6 +13,7 @@
 #include <stdarg.h>
 #include <unistd.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 #include <umask.h>
diff --git a/src/system/libroot/posix/glibc/arch/m68k/Jamfile 
b/src/system/libroot/posix/glibc/arch/m68k/Jamfile
index d93cba6..4686573 100644
--- a/src/system/libroot/posix/glibc/arch/m68k/Jamfile
+++ b/src/system/libroot/posix/glibc/arch/m68k/Jamfile
@@ -12,6 +12,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
 SubDirHdrs $(HAIKU_TOP) src system libroot posix glibc arch generic ;
 
+UsePrivateHeaders libroot ;
+
 
 if $(OPTIM) = -O0 {
        OPTIM = -O ;
diff --git a/src/system/libroot/posix/glibc/arch/ppc/Jamfile 
b/src/system/libroot/posix/glibc/arch/ppc/Jamfile
index 44ad8c5..a01f1a5 100644
--- a/src/system/libroot/posix/glibc/arch/ppc/Jamfile
+++ b/src/system/libroot/posix/glibc/arch/ppc/Jamfile
@@ -11,6 +11,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
 SubDirHdrs $(HAIKU_TOP) src system libroot posix glibc arch generic ;
 
+UsePrivateHeaders libroot ;
+
 
 if $(OPTIM) = -O0 {
        OPTIM = -O ;
diff --git a/src/system/libroot/posix/glibc/arch/x86/Jamfile 
b/src/system/libroot/posix/glibc/arch/x86/Jamfile
index 0630d60..ebd9e30 100644
--- a/src/system/libroot/posix/glibc/arch/x86/Jamfile
+++ b/src/system/libroot/posix/glibc/arch/x86/Jamfile
@@ -10,6 +10,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
 SubDirHdrs $(HAIKU_TOP) src system libroot posix glibc arch generic ;
 
+UsePrivateHeaders libroot ;
+
 if $(OPTIM) = -O0 {
        OPTIM = -O ;
 }
diff --git a/src/system/libroot/posix/glibc/iconv/Jamfile 
b/src/system/libroot/posix/glibc/iconv/Jamfile
index 8689bca..01be0be 100644
--- a/src/system/libroot/posix/glibc/iconv/Jamfile
+++ b/src/system/libroot/posix/glibc/iconv/Jamfile
@@ -10,6 +10,9 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
iconv ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
+UsePrivateHeaders libroot ;
+
+
 SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;
 
 MergeObject posix_gnu_iconv.o :
diff --git a/src/system/libroot/posix/glibc/include/bits/errno.h 
b/src/system/libroot/posix/glibc/include/bits/errno.h
index 30938a7..28f0a54 100644
--- a/src/system/libroot/posix/glibc/include/bits/errno.h
+++ b/src/system/libroot/posix/glibc/include/bits/errno.h
@@ -17,4 +17,4 @@
    02111-1307 USA.  */
 #include_next <errno.h>
 
-#define __set_errno(val) errno = (val)
+#include <errno_private.h>
diff --git a/src/system/libroot/posix/glibc/libio/Jamfile 
b/src/system/libroot/posix/glibc/libio/Jamfile
index 2e10d5a..ca7e0d1 100644
--- a/src/system/libroot/posix/glibc/libio/Jamfile
+++ b/src/system/libroot/posix/glibc/libio/Jamfile
@@ -11,6 +11,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
locale ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc iconv ;
 
+UsePrivateHeaders libroot ;
+
 # For now, all wide character functions are disabled,
 # obprintf() is also disabled, because we don't have
 # obstack functionality
diff --git a/src/system/libroot/posix/glibc/libio/fileops.c 
b/src/system/libroot/posix/glibc/libio/fileops.c
index ad75784..cdae313 100644
--- a/src/system/libroot/posix/glibc/libio/fileops.c
+++ b/src/system/libroot/posix/glibc/libio/fileops.c
@@ -50,12 +50,6 @@
 # include <shlib-compat.h>
 #endif
 #endif
-#ifndef errno
-extern int errno;
-#endif
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 
 #ifdef _LIBC
 /*# define open(Name, Flags, Prot) __open (Name, Flags, Prot)
diff --git a/src/system/libroot/posix/glibc/libio/ioseekoff.c 
b/src/system/libroot/posix/glibc/libio/ioseekoff.c
index fe3f57e..154a343 100644
--- a/src/system/libroot/posix/glibc/libio/ioseekoff.c
+++ b/src/system/libroot/posix/glibc/libio/ioseekoff.c
@@ -28,12 +28,6 @@
 #include <libioP.h>
 #include <stdlib.h>
 #include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 
 _IO_off64_t
 _IO_seekoff_unlocked (fp, offset, dir, mode)
diff --git a/src/system/libroot/posix/glibc/libio/libioP.h 
b/src/system/libroot/posix/glibc/libio/libioP.h
index 4c808e4..cb1a48a 100644
--- a/src/system/libroot/posix/glibc/libio/libioP.h
+++ b/src/system/libroot/posix/glibc/libio/libioP.h
@@ -29,9 +29,6 @@
 #define _LIBIO_P_H_
 
 #include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 #if defined __GLIBC__ && __GLIBC__ >= 2
 # include <bits/libc-lock.h>
 #else
diff --git a/src/system/libroot/posix/glibc/libio/oldfileops.c 
b/src/system/libroot/posix/glibc/libio/oldfileops.c
index cb1bb2e..3e22c83 100644
--- a/src/system/libroot/posix/glibc/libio/oldfileops.c
+++ b/src/system/libroot/posix/glibc/libio/oldfileops.c
@@ -44,12 +44,6 @@
 #ifdef __STDC__
 #include <stdlib.h>
 #endif
-#ifndef errno
-extern int errno;
-#endif
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 
 
 #ifdef _LIBC
diff --git a/src/system/libroot/posix/glibc/misc/Jamfile 
b/src/system/libroot/posix/glibc/misc/Jamfile
index 0dcf7af..52767e5 100644
--- a/src/system/libroot/posix/glibc/misc/Jamfile
+++ b/src/system/libroot/posix/glibc/misc/Jamfile
@@ -10,6 +10,9 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
misc ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
+UsePrivateHeaders libroot ;
+
+
 SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;
 
 MergeObject posix_gnu_misc.o :
diff --git a/src/system/libroot/posix/glibc/stdio-common/Jamfile 
b/src/system/libroot/posix/glibc/stdio-common/Jamfile
index b13bad0..bea6ede 100644
--- a/src/system/libroot/posix/glibc/stdio-common/Jamfile
+++ b/src/system/libroot/posix/glibc/stdio-common/Jamfile
@@ -11,7 +11,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
stdio-common ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc locale ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
-# ToDo: for now, all wide character functions are disabled
+UsePrivateHeaders libroot ;
+
 
 MergeObject posix_gnu_stdio.o : #_common.o :
        _itoa.c
diff --git a/src/system/libroot/posix/glibc/stdio-common/tempname.c 
b/src/system/libroot/posix/glibc/stdio-common/tempname.c
index e463760..902dc4b 100644
--- a/src/system/libroot/posix/glibc/stdio-common/tempname.c
+++ b/src/system/libroot/posix/glibc/stdio-common/tempname.c
@@ -24,9 +24,6 @@
 #include <assert.h>
 
 #include <errno.h>
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 
 #include <stdio.h>
 #ifndef P_tmpdir
diff --git a/src/system/libroot/posix/glibc/stdio-common/vfscanf.c 
b/src/system/libroot/posix/glibc/stdio-common/vfscanf.c
index 41504c8..10d09a9 100644
--- a/src/system/libroot/posix/glibc/stdio-common/vfscanf.c
+++ b/src/system/libroot/posix/glibc/stdio-common/vfscanf.c
@@ -605,12 +605,12 @@ __vfscanf (FILE *s, const char *format, va_list argptr)
        {
          /* Eat whitespace.  */
          int save_errno = errno;
-         errno = 0;
+         __set_errno(0);
          do
            if (inchar () == EOF && errno == EINTR)
              input_error ();
          while (ISSPACE (c));
-         errno = save_errno;
+         __set_errno(save_errno);
          ungetc (c, s);
          skip_space = 0;
        }
diff --git a/src/system/libroot/posix/glibc/stdlib/Jamfile 
b/src/system/libroot/posix/glibc/stdlib/Jamfile
index acf6be7..35b07cc 100644
--- a/src/system/libroot/posix/glibc/stdlib/Jamfile
+++ b/src/system/libroot/posix/glibc/stdlib/Jamfile
@@ -7,6 +7,8 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
locale ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc stdlib ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
+UsePrivateHeaders libroot ;
+
 SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;
 
 MergeObject posix_gnu_stdlib.o :
diff --git a/src/system/libroot/posix/glibc/stdlib/strtol.c 
b/src/system/libroot/posix/glibc/stdlib/strtol.c
index d2e09c8..eb8602f 100644
--- a/src/system/libroot/posix/glibc/stdlib/strtol.c
+++ b/src/system/libroot/posix/glibc/stdlib/strtol.c
@@ -29,12 +29,6 @@
 
 #include <ctype.h>
 #include <errno.h>
-#ifndef errno
-extern int errno;
-#endif
-#ifndef __set_errno
-# define __set_errno(Val) errno = (Val)
-#endif
 
 #ifdef HAVE_LIMITS_H
 # include <limits.h>
@@ -532,7 +526,7 @@ noconv:
 
   return 0L;
 }
-
+
 /* External user entry point.  */
 
 #if _LIBC - 0 == 0
diff --git a/src/system/libroot/posix/glibc/wcsmbs/Jamfile 
b/src/system/libroot/posix/glibc/wcsmbs/Jamfile
index b8c4768..b2ed36c 100644
--- a/src/system/libroot/posix/glibc/wcsmbs/Jamfile
+++ b/src/system/libroot/posix/glibc/wcsmbs/Jamfile
@@ -12,6 +12,9 @@ SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc 
stdlib ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ctype ;
 SubDirSysHdrs $(HAIKU_TOP) src system libroot posix glibc ;
 
+UsePrivateHeaders libroot ;
+
+
 SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ;
 
 MergeObject posix_gnu_wcsmbs.o :
diff --git a/src/system/libroot/posix/glob.c b/src/system/libroot/posix/glob.c
index 397a40c..83365ee 100644
--- a/src/system/libroot/posix/glob.c
+++ b/src/system/libroot/posix/glob.c
@@ -87,6 +87,8 @@ static char sccsid[] = "@(#)glob.c    8.3 (Berkeley) 
10/13/93";
 #include <unistd.h>
 #include <wchar.h>
 
+#include <errno_private.h>
+
 #ifndef __HAIKU__
 #      include "collate.h"
 #endif
@@ -155,7 +157,7 @@ static int   glob1(Char *, glob_t *, size_t *);
 static int      glob2(Char *, Char *, Char *, Char *, glob_t *, size_t *);
 static int      glob3(Char *, Char *, Char *, Char *, Char *, glob_t *, size_t 
*);
 static int      globextend(const Char *, glob_t *, size_t *);
-static const Char *    
+static const Char *
                 globtilde(const Char *, Char *, size_t, glob_t *);
 static int      globexp1(const Char *, glob_t *, size_t *);
 static int      globexp2(const Char *, const Char *, glob_t *, int *, size_t 
*);
@@ -378,8 +380,8 @@ globtilde(const Char *pattern, Char *patbuf, size_t 
patbuf_len, glob_t *pglob)
        if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE))
                return pattern;
 
-       /* 
-        * Copy up to the end of the string or / 
+       /*
+        * Copy up to the end of the string or /
         */
        eb = &patbuf[patbuf_len - 1];
        for (p = pattern + 1, h = (char *) patbuf;
@@ -625,7 +627,7 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
        if (pathend > pathend_last)
                return (GLOB_ABORTED);
        *pathend = EOS;
-       errno = 0;
+       __set_errno(0);
 
        if ((dirp = g_opendir(pathbuf, pglob)) == NULL) {
                /* TODO: don't call for ENOENT or ENOTDIR? */
@@ -711,7 +713,7 @@ globextend(const Char *path, glob_t *pglob, size_t *limit)
        const Char *p;
 
        if (*limit && pglob->gl_pathc > *limit) {
-               errno = 0;
+               __set_errno(0);
                return (GLOB_NOSPACE);
        }
 
@@ -850,7 +852,7 @@ g_lstat(Char *fn, struct stat *sb, glob_t *pglob)
        char buf[MAXPATHLEN];
 
        if (g_Ctoc(fn, buf, sizeof(buf))) {
-               errno = ENAMETOOLONG;
+               __set_errno(ENAMETOOLONG);
                return (-1);
        }
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
@@ -864,7 +866,7 @@ g_stat(Char *fn, struct stat *sb, glob_t *pglob)
        char buf[MAXPATHLEN];
 
        if (g_Ctoc(fn, buf, sizeof(buf))) {
-               errno = ENAMETOOLONG;
+               __set_errno(ENAMETOOLONG);
                return (-1);
        }
        if (pglob->gl_flags & GLOB_ALTDIRFUNC)
diff --git a/src/system/libroot/posix/grp.cpp b/src/system/libroot/posix/grp.cpp
index e28db52..f8faac4 100644
--- a/src/system/libroot/posix/grp.cpp
+++ b/src/system/libroot/posix/grp.cpp
@@ -13,6 +13,7 @@
 
 #include <OS.h>
 
+#include <errno_private.h>
 #include <libroot_private.h>
 #include <RegistrarDefs.h>
 #include <user_group.h>
@@ -130,7 +131,7 @@ getgrent(void)
        int status = getgrent_r(&sGroupBuffer, sGroupStringBuffer,
                sizeof(sGroupStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -190,7 +191,7 @@ getgrnam(const char *name)
        int status = getgrnam_r(name, &sGroupBuffer, sGroupStringBuffer,
                sizeof(sGroupStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -210,7 +211,7 @@ getgrgid(gid_t gid)
        int status = getgrgid_r(gid, &sGroupBuffer, sGroupStringBuffer,
                sizeof(sGroupStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
diff --git a/src/system/libroot/posix/locale/Jamfile 
b/src/system/libroot/posix/locale/Jamfile
index f65b334..1d96bba 100644
--- a/src/system/libroot/posix/locale/Jamfile
+++ b/src/system/libroot/posix/locale/Jamfile
@@ -1,6 +1,7 @@
 SubDir HAIKU_TOP src system libroot posix locale ;
 
 UsePrivateHeaders
+       [ FDirName libroot ]
        [ FDirName libroot locale ]
        [ FDirName libroot time ]
 ;
diff --git a/src/system/libroot/posix/locale/wctype.cpp 
b/src/system/libroot/posix/locale/wctype.cpp
index 05df504..248079c 100644
--- a/src/system/libroot/posix/locale/wctype.cpp
+++ b/src/system/libroot/posix/locale/wctype.cpp
@@ -8,6 +8,8 @@
 #include <string.h>
 #include <wctype.h>
 
+#include <errno_private.h>
+
 #include "LocaleBackend.h"
 
 
@@ -187,7 +189,7 @@ towctrans(wint_t wc, wctrans_t transition)
        status_t status = gLocaleBackend->ToWCTrans(wc, transition, result);
 
        if (status != B_OK)
-               errno = EINVAL;
+               __set_errno(EINVAL);
 
        return result;
 }
@@ -204,7 +206,7 @@ wctrans(const char *charClass)
                        return _ISupper;
        }
 
-       errno = EINVAL;
+       __set_errno(EINVAL);
        return 0;
 }
 
diff --git a/src/system/libroot/posix/malloc/wrapper.cpp 
b/src/system/libroot/posix/malloc/wrapper.cpp
index 5741107..2af067f 100644
--- a/src/system/libroot/posix/malloc/wrapper.cpp
+++ b/src/system/libroot/posix/malloc/wrapper.cpp
@@ -29,6 +29,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include <errno_private.h>
 #include <user_thread.h>
 
 #include "tracing_config.h"
@@ -154,7 +155,7 @@ add_address(void* address, size_t size)
        };
 
        stack_frame* frame = (stack_frame*)get_stack_frame();
-       
+
        for (int i = 0; i < HEAP_CALL_STACK_SIZE; i++) {
                if (frame != NULL) {
                        b->setCallStack(i, frame->return_address);
@@ -272,7 +273,7 @@ malloc(size_t size)
        void *addr = pHeap->getHeap(pHeap->getHeapIndex()).malloc(size);
        if (addr == NULL) {
                undefer_signals();
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                KTRACE("malloc(%lu) -> NULL", size);
                return NULL;
        }
@@ -308,7 +309,7 @@ calloc(size_t nelem, size_t elsize)
        void *ptr = pHeap->getHeap(pHeap->getHeapIndex()).malloc(size);
        if (ptr == NULL) {
                undefer_signals();
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                KTRACE("calloc(%lu, %lu) -> NULL", nelem, elsize);
                return NULL;
        }
@@ -373,7 +374,7 @@ memalign(size_t alignment, size_t size)
                size);
        if (addr == NULL) {
                undefer_signals();
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                KTRACE("memalign(%lu, %lu) -> NULL", alignment, size);
                return NULL;
        }
@@ -469,7 +470,7 @@ realloc(void *ptr, size_t size)
        void *buffer = malloc(size);
        if (buffer == NULL) {
                // Allocation failed, leave old block and return
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                KTRACE("realloc(%p, %lu) -> NULL", ptr, size);
                return NULL;
        }
diff --git a/src/system/libroot/posix/malloc_debug/Jamfile 
b/src/system/libroot/posix/malloc_debug/Jamfile
index 4def90d..53c2d86 100644
--- a/src/system/libroot/posix/malloc_debug/Jamfile
+++ b/src/system/libroot/posix/malloc_debug/Jamfile
@@ -1,7 +1,7 @@
 SubDir HAIKU_TOP src system libroot posix malloc_debug ;
 
 UsePrivateSystemHeaders ;
-UsePrivateHeaders shared ;
+UsePrivateHeaders libroot shared ;
 
 MergeObject posix_malloc_debug.o :
        heap.cpp
diff --git a/src/system/libroot/posix/malloc_debug/heap.cpp 
b/src/system/libroot/posix/malloc_debug/heap.cpp
index c3a5097..0753f67 100644
--- a/src/system/libroot/posix/malloc_debug/heap.cpp
+++ b/src/system/libroot/posix/malloc_debug/heap.cpp
@@ -19,6 +19,7 @@
 #include <errno.h>
 #include <sys/mman.h>
 
+#include <errno_private.h>
 #include <locks.h>
 #include <syscalls.h>
 
diff --git a/src/system/libroot/posix/poll.c b/src/system/libroot/posix/poll.c
index 7898059..cbd0f37 100644
--- a/src/system/libroot/posix/poll.c
+++ b/src/system/libroot/posix/poll.c
@@ -11,6 +11,7 @@
 
 #include <syscall_utils.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
diff --git a/src/system/libroot/posix/pwd.cpp b/src/system/libroot/posix/pwd.cpp
index aa4ac55..57839ba 100644
--- a/src/system/libroot/posix/pwd.cpp
+++ b/src/system/libroot/posix/pwd.cpp
@@ -13,6 +13,7 @@
 
 #include <OS.h>
 
+#include <errno_private.h>
 #include <libroot_private.h>
 #include <RegistrarDefs.h>
 #include <user_group.h>
@@ -128,7 +129,7 @@ getpwent(void)
        int status = getpwent_r(&sPasswdBuffer, sPasswdStringBuffer,
                sizeof(sPasswdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -188,7 +189,7 @@ getpwnam(const char *name)
        int status = getpwnam_r(name, &sPasswdBuffer, sPasswdStringBuffer,
                sizeof(sPasswdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -208,7 +209,7 @@ getpwuid(uid_t uid)
        int status = getpwuid_r(uid, &sPasswdBuffer, sPasswdStringBuffer,
                sizeof(sPasswdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
diff --git a/src/system/libroot/posix/pwd_query.c 
b/src/system/libroot/posix/pwd_query.c
index 735d0e8..1fe7f57 100644
--- a/src/system/libroot/posix/pwd_query.c
+++ b/src/system/libroot/posix/pwd_query.c
@@ -20,7 +20,9 @@
 #include <Debug.h>
 #include <TypeConstants.h>
 
-/* 
+#include <errno_private.h>
+
+/*
  * Some notes.
  * Users are stored in an fs node (not necessarily a regular file,
  * that could be a dir, even the user's home dir,
@@ -78,16 +80,16 @@ static int32 pw_tls_id;
 typedef struct pw_tls {
        DIR *grent_query;
        DIR *pwent_query;
-       
+
        int gridx;
        int pwidx;
-       
+
        char grfile[B_PATH_NAME_LENGTH+1]; /* current group's cached file path 
*/
        char pwfile[B_PATH_NAME_LENGTH+1]; /* current user's cached file path */
-       
+
        struct group grent;
        char grbuff[GRBUFFSZ]; /* XXX: merge with pwbuff ? */
-       
+
        struct passwd pwent;
        char pwbuff[PWBUFFSZ];
 } pw_tls_t;
@@ -96,7 +98,7 @@ struct pw_tls *get_pw_tls(void)
 {
        pw_tls_t *p = (pw_tls_t *)tls_get(pw_tls_id);
        PRINT(("%s()\n", __FUNCTION__));
-       
+
        if (!p) {
                p = (pw_tls_t *)malloc(sizeof(pw_tls_t));
                if (!p)
@@ -117,7 +119,7 @@ int dentopen(struct dirent *dent, char *path)
        dent->d_dev = boot_device;
        err = get_path_for_dirent(dent, path, B_PATH_NAME_LENGTH);
        if ((err < 0) || (path[0] != '/')) {
-               errno = err;
+               __set_errno(err);
                return -1;
        }
        PRINT(("%s: open(%s)\n", __FUNCTION__, path));
@@ -178,7 +180,7 @@ void endgrent(void)
        pw_tls_t *p;
        PRINT(("%s()\n", __FUNCTION__));
        p = get_pw_tls();
-       
+
        if (p->grent_query)
                fs_close_query(p->grent_query);
        p->grent_query = NULL;
@@ -203,7 +205,7 @@ PRINT(("getgrent_r: grq = %p, idx = %d\n", p->grent_query, 
p->gridx));
                setgrent(); /* y0u clumsy app! */
        if (!p->grent_query)
                return EIO; /* something happened... */
-       errno = 0;
+       __set_errno(0);
        dent = fs_read_query(p->grent_query);
        *gbufp = NULL;
        if (!dent) {
@@ -238,12 +240,12 @@ struct group *getgrent(void)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
        err = getgrent_r(&p->grent, p->grbuff, GRBUFFSZ, &ent);
        if (err < 0) {
-               errno = err;
+               __set_errno(err);
                return NULL;
        }
        if (!ent)
@@ -265,17 +267,17 @@ struct group *getgrgid(gid_t gid)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
-       
+
        /* reusing path */
        sprintf(p->grfile, QT_GR_GID, gid);
        query = fs_open_query(boot_device, p->grfile, 0);
        PRINT(("q: %p\n", query));
        if (!query)
                return NULL;
-       
+
        dent = fs_read_query(query);
        if (!dent) {
                fs_close_query(query);
@@ -291,7 +293,7 @@ struct group *getgrgid(gid_t gid)
        if (err)
                return NULL;
        return &p->grent;
-       
+
 }
 
 /* by name */
@@ -307,12 +309,12 @@ struct group *getgrnam(const char *name)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
-       
+
        if (!name || strlen(name) > GR_MAX_NAME) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return NULL;
        }
        /* reusing path */
@@ -321,7 +323,7 @@ struct group *getgrnam(const char *name)
        PRINT(("q: %p\n", query));
        if (!query)
                return NULL;
-       
+
        dent = fs_read_query(query);
        if (!dent) {
                fs_close_query(query);
@@ -337,7 +339,7 @@ struct group *getgrnam(const char *name)
        if (err)
                return NULL;
        return &p->grent;
-       
+
 }
 
 
@@ -455,7 +457,7 @@ void endpwent(void)
        pw_tls_t *p;
        PRINT(("%s()\n", __FUNCTION__));
        p = get_pw_tls();
-       
+
        if (p->pwent_query)
                fs_close_query(p->pwent_query);
        p->pwent_query = NULL;
@@ -480,7 +482,7 @@ PRINT(("getpwent_r: pwq = %p, idx = %d\n", p->pwent_query, 
p->pwidx));
                setpwent(); /* y0u clumsy app! */
        if (!p->pwent_query)
                return EIO; /* something happened... */
-       errno = 0;
+       __set_errno(0);
        dent = fs_read_query(p->pwent_query);
        *pwbufp = NULL;
        if (!dent) {
@@ -515,12 +517,12 @@ struct passwd *getpwent(void)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
        err = getpwent_r(&p->pwent, p->pwbuff, PWBUFFSZ, &ent);
        if (err < 0) {
-               errno = err;
+               __set_errno(err);
                return NULL;
        }
        if (!ent)
@@ -542,10 +544,10 @@ struct passwd *getpwuid(uid_t uid)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
-       
+
        /* reusing path */
        sprintf(p->pwfile, QT_PW_UID, uid);
        PRINT(("%s: query(%s)\n", __FUNCTION__, p->pwfile));
@@ -553,7 +555,7 @@ struct passwd *getpwuid(uid_t uid)
        PRINT(("q: %p\n", query));
        if (!query)
                return NULL;
-       
+
        dent = fs_read_query(query);
        if (!dent) {
                fs_close_query(query);
@@ -569,7 +571,7 @@ struct passwd *getpwuid(uid_t uid)
        if (err)
                return NULL;
        return &p->pwent;
-       
+
 }
 
 /* by name */
@@ -585,12 +587,12 @@ struct passwd *getpwnam(const char *name)
        p = get_pw_tls();
        if (!p) {
                /* we are really bork */
-               errno = ENOMEM;
+               __set_errno(ENOMEM);
                return NULL;
        }
-       
+
        if (!name || strlen(name) > PW_MAX_NAME) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return NULL;
        }
        /* reusing path */
@@ -600,7 +602,7 @@ struct passwd *getpwnam(const char *name)
        PRINT(("q: %p\n", query));
        if (!query)
                return NULL;
-       
+
        dent = fs_read_query(query);
        if (!dent) {
                fs_close_query(query);
@@ -617,7 +619,7 @@ struct passwd *getpwnam(const char *name)
        if (err)
                return NULL;
        return &p->pwent;
-       
+
 }
 
 void __init_pwd_backend(void)
@@ -631,7 +633,7 @@ void __init_pwd_backend(void)
 /*
 void __fini_pwd_backend(void)
 {
-       
+
 }
 */
 
diff --git a/src/system/libroot/posix/scheduler.cpp 
b/src/system/libroot/posix/scheduler.cpp
index 95799b6..f56543d 100644
--- a/src/system/libroot/posix/scheduler.cpp
+++ b/src/system/libroot/posix/scheduler.cpp
@@ -10,6 +10,7 @@
 
 #include <OS.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -32,7 +33,7 @@ sched_get_priority_min(int policy)
                        return B_LOW_PRIORITY;
 
                default:
-                       errno = EINVAL;
+                       __set_errno(EINVAL);
                        return -1;
        }
 }
@@ -49,7 +50,7 @@ sched_get_priority_max(int policy)
                        return B_URGENT_DISPLAY_PRIORITY;
 
                default:
-                       errno = EINVAL;
+                       __set_errno(EINVAL);
                        return -1;
        }
 }
diff --git a/src/system/libroot/posix/semaphore.cpp 
b/src/system/libroot/posix/semaphore.cpp
index 9564783..b96b835 100644
--- a/src/system/libroot/posix/semaphore.cpp
+++ b/src/system/libroot/posix/semaphore.cpp
@@ -13,6 +13,7 @@
 #include <OS.h>
 
 #include <AutoDeleter.h>
+#include <errno_private.h>
 #include <posix/realtime_sem_defs.h>
 #include <syscall_utils.h>
 #include <syscalls.h>
@@ -22,7 +23,7 @@ sem_t*
 sem_open(const char* name, int openFlags,...)
 {
        if (name == NULL) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return SEM_FAILED;
        }
 
@@ -46,7 +47,7 @@ sem_open(const char* name, int openFlags,...)
        // structure, otherwise we will delete it later.
        sem_t* sem = (sem_t*)malloc(sizeof(sem_t));
        if (sem == NULL) {
-               errno = B_NO_MEMORY;
+               __set_errno(B_NO_MEMORY);
                return SEM_FAILED;
        }
        MemoryDeleter semDeleter(sem);
@@ -56,7 +57,7 @@ sem_open(const char* name, int openFlags,...)
        status_t error = _kern_realtime_sem_open(name, openFlags, mode, 
semCount,
                sem, &usedSem);
        if (error != B_OK) {
-               errno = error;
+               __set_errno(error);
                return SEM_FAILED;
        }
 
diff --git a/src/system/libroot/posix/shadow.cpp 
b/src/system/libroot/posix/shadow.cpp
index 999f6b3..5f3d32b 100644
--- a/src/system/libroot/posix/shadow.cpp
+++ b/src/system/libroot/posix/shadow.cpp
@@ -14,6 +14,7 @@
 #include <OS.h>
 
 #include <AutoDeleter.h>
+#include <errno_private.h>
 #include <libroot_private.h>
 #include <RegistrarDefs.h>
 #include <user_group.h>
@@ -82,7 +83,7 @@ getspent(void)
        int status = getspent_r(&sShadowPwdBuffer, sShadowPwdStringBuffer,
                sizeof(sShadowPwdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -142,7 +143,7 @@ getspnam(const char *name)
        int status = getspnam_r(name, &sShadowPwdBuffer, sShadowPwdStringBuffer,
                sizeof(sShadowPwdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -200,7 +201,7 @@ sgetspent(const char* line)
        int status = sgetspent_r(line, &sShadowPwdBuffer, 
sShadowPwdStringBuffer,
                sizeof(sShadowPwdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -252,7 +253,7 @@ fgetspent(FILE* file)
        int status = fgetspent_r(file, &sShadowPwdBuffer, 
sShadowPwdStringBuffer,
                sizeof(sShadowPwdStringBuffer), &result);
        if (status != 0)
-               errno = status;
+               __set_errno(status);
        return result;
 }
 
@@ -265,7 +266,7 @@ fgetspent_r(FILE* file, struct spwd* spwd, char* buffer, 
size_t bufferSize,
 
        // read a line
        char lineBuffer[LINE_MAX + 1];
-       errno = 0;
+       __set_errno(0);
        char* line = fgets(lineBuffer, sizeof(lineBuffer), file);
        if (line == NULL) {
                if (errno != 0)
diff --git a/src/system/libroot/posix/signal/kill.c 
b/src/system/libroot/posix/signal/kill.c
index ed01a39..999366a 100644
--- a/src/system/libroot/posix/signal/kill.c
+++ b/src/system/libroot/posix/signal/kill.c
@@ -9,6 +9,7 @@
 
 #include <OS.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -18,7 +19,7 @@ kill(pid_t pid, int sig)
        status_t status;
 
        if (sig < 0) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -28,7 +29,7 @@ kill(pid_t pid, int sig)
                if (status == B_BAD_THREAD_ID || status == B_BAD_TEAM_ID)
                        status = ESRCH;
 
-               errno = status;
+               __set_errno(status);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/signal/killpg.cpp 
b/src/system/libroot/posix/signal/killpg.cpp
index ef00d72..0ee8e64 100644
--- a/src/system/libroot/posix/signal/killpg.cpp
+++ b/src/system/libroot/posix/signal/killpg.cpp
@@ -7,6 +7,8 @@
 #include <errno.h>
 #include <signal.h>
 
+#include <errno_private.h>
+
 
 int
 killpg(pid_t processGroupID, int signal)
@@ -14,7 +16,7 @@ killpg(pid_t processGroupID, int signal)
        if (processGroupID > 1)
                return kill(-processGroupID, signal);
        else {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 }
diff --git a/src/system/libroot/posix/signal/set_signal_mask.cpp 
b/src/system/libroot/posix/signal/set_signal_mask.cpp
index 9696693..6f3e1e7 100644
--- a/src/system/libroot/posix/signal/set_signal_mask.cpp
+++ b/src/system/libroot/posix/signal/set_signal_mask.cpp
@@ -15,6 +15,7 @@
 #include <symbol_versioning.h>
 #include <syscalls.h>
 
+#include <errno_private.h>
 #include <signal_private.h>
 
 
diff --git a/src/system/libroot/posix/signal/set_signal_stack.c 
b/src/system/libroot/posix/signal/set_signal_stack.c
index 84e0481..89b547d 100644
--- a/src/system/libroot/posix/signal/set_signal_stack.c
+++ b/src/system/libroot/posix/signal/set_signal_stack.c
@@ -8,6 +8,7 @@
 
 #include <errno.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -23,7 +24,7 @@ set_signal_stack(void *ptr, size_t size)
 
        status = _kern_set_signal_stack(&alternateStack, NULL);
        if (status < B_OK)
-               errno = status;
+               __set_errno(status);
 }
 
 
diff --git a/src/system/libroot/posix/signal/sigaction.cpp 
b/src/system/libroot/posix/signal/sigaction.cpp
index 8025ff4..f8dea2e 100644
--- a/src/system/libroot/posix/signal/sigaction.cpp
+++ b/src/system/libroot/posix/signal/sigaction.cpp
@@ -17,6 +17,7 @@
 #include <symbol_versioning.h>
 #include <syscalls.h>
 
+#include <errno_private.h>
 #include <signal_private.h>
 
 
diff --git a/src/system/libroot/posix/signal/sigaltstack.c 
b/src/system/libroot/posix/signal/sigaltstack.c
index d191a16..07d62e3 100644
--- a/src/system/libroot/posix/signal/sigaltstack.c
+++ b/src/system/libroot/posix/signal/sigaltstack.c
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <signal.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -15,7 +16,7 @@ sigaltstack(const stack_t *alternateStack, stack_t 
*oldAlternateStack)
 {
        status_t status =_kern_set_signal_stack(alternateStack, 
oldAlternateStack);
        if (status < B_OK) {
-               errno = status;
+               __set_errno(status);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/signal/signal.cpp 
b/src/system/libroot/posix/signal/signal.cpp
index 8f3495f..e99c51c 100644
--- a/src/system/libroot/posix/signal/signal.cpp
+++ b/src/system/libroot/posix/signal/signal.cpp
@@ -15,6 +15,7 @@
 
 #include <symbol_versioning.h>
 
+#include <errno_private.h>
 #include <signal_private.h>
 
 
@@ -41,7 +42,7 @@ __signal_beos(int signal, __sighandler_t signalHandler)
 {
        // check signal range
        if (signal < 0 || signal > MAX_SIGNAL_NUMBER_BEOS) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return SIG_ERR;
        }
 
diff --git a/src/system/libroot/posix/signal/sigpending.cpp 
b/src/system/libroot/posix/signal/sigpending.cpp
index 24d6288..b923a32 100644
--- a/src/system/libroot/posix/signal/sigpending.cpp
+++ b/src/system/libroot/posix/signal/sigpending.cpp
@@ -14,6 +14,7 @@
 
 #include <syscall_utils.h>
 
+#include <errno_private.h>
 #include <symbol_versioning.h>
 #include <syscalls.h>
 
diff --git a/src/system/libroot/posix/signal/sigqueue.cpp 
b/src/system/libroot/posix/signal/sigqueue.cpp
index 129e29c..8ad1a1f 100644
--- a/src/system/libroot/posix/signal/sigqueue.cpp
+++ b/src/system/libroot/posix/signal/sigqueue.cpp
@@ -10,6 +10,7 @@
 
 #include <syscall_utils.h>
 
+#include <errno_private.h>
 #include <signal_defs.h>
 #include <syscalls.h>
 
diff --git a/src/system/libroot/posix/signal/sigset_accessors.cpp 
b/src/system/libroot/posix/signal/sigset_accessors.cpp
index cf304b6..6b630b7 100644
--- a/src/system/libroot/posix/signal/sigset_accessors.cpp
+++ b/src/system/libroot/posix/signal/sigset_accessors.cpp
@@ -17,6 +17,7 @@
 
 #include <symbol_versioning.h>
 
+#include <errno_private.h>
 #include <signal_private.h>
 
 
@@ -43,7 +44,7 @@ int
 __sigismember_beos(const sigset_t_beos* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER_BEOS) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -55,7 +56,7 @@ int
 __sigaddset_beos(sigset_t_beos* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER_BEOS) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -68,7 +69,7 @@ int
 __sigdelset_beos(sigset_t_beos* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER_BEOS) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -100,7 +101,7 @@ int
 __sigismember(const sigset_t* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -112,7 +113,7 @@ int
 __sigaddset(sigset_t* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
@@ -125,7 +126,7 @@ int
 __sigdelset(sigset_t* set, int signal)
 {
        if (signal <= 0 || signal > MAX_SIGNAL_NUMBER) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/signal/sigsuspend.cpp 
b/src/system/libroot/posix/signal/sigsuspend.cpp
index 5b9a1c5..21fc684 100644
--- a/src/system/libroot/posix/signal/sigsuspend.cpp
+++ b/src/system/libroot/posix/signal/sigsuspend.cpp
@@ -18,6 +18,7 @@
 #include <symbol_versioning.h>
 #include <syscalls.h>
 
+#include <errno_private.h>
 #include <signal_private.h>
 
 
@@ -32,7 +33,7 @@ __sigsuspend_beos(const sigset_t_beos* beosMask)
 int
 __sigsuspend(const sigset_t* mask)
 {
-       errno = _kern_sigsuspend(mask);
+       __set_errno(_kern_sigsuspend(mask));
 
        pthread_testcancel();
 
diff --git a/src/system/libroot/posix/signal/sigtimedwait.cpp 
b/src/system/libroot/posix/signal/sigtimedwait.cpp
index 1ae8382..7e18787 100644
--- a/src/system/libroot/posix/signal/sigtimedwait.cpp
+++ b/src/system/libroot/posix/signal/sigtimedwait.cpp
@@ -11,6 +11,7 @@
 
 #include <syscall_utils.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
diff --git a/src/system/libroot/posix/signal/strsignal.cpp 
b/src/system/libroot/posix/signal/strsignal.cpp
index 3ba17f9..7a92a41 100644
--- a/src/system/libroot/posix/signal/strsignal.cpp
+++ b/src/system/libroot/posix/signal/strsignal.cpp
@@ -14,6 +14,7 @@
 #include <signal.h>
 #include <stdio.h>
 
+#include <errno_private.h>
 #include <signal_defs.h>
 
 
diff --git a/src/system/libroot/posix/stdio/fclose.c 
b/src/system/libroot/posix/stdio/fclose.c
index b2a0567..23d1819 100644
--- a/src/system/libroot/posix/stdio/fclose.c
+++ b/src/system/libroot/posix/stdio/fclose.c
@@ -41,6 +41,9 @@ static char rcsid[] = "$OpenBSD: fclose.c,v 1.2 1996/08/19 
08:32:19 tholo Exp $"
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 int
@@ -50,7 +53,7 @@ fclose(fp)
        register int r;
 
        if (fp->_flags == 0) {  /* not open! */
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
        r = fp->_flags & __SWR ? __sflush(fp) : 0;
diff --git a/src/system/libroot/posix/stdio/fflush.c 
b/src/system/libroot/posix/stdio/fflush.c
index e2fe1bf..5becca3 100644
--- a/src/system/libroot/posix/stdio/fflush.c
+++ b/src/system/libroot/posix/stdio/fflush.c
@@ -40,6 +40,9 @@ static char rcsid[] = "$OpenBSD: fflush.c,v 1.2 1996/08/19 
08:32:26 tholo Exp $"
 
 #include <errno.h>
 #include <stdio.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 /* Flush a single file, or (if fp is NULL) all files.  */
@@ -50,7 +53,7 @@ fflush(fp)
        if (fp == NULL)
                return (_fwalk(__sflush));
        if ((fp->_flags & (__SWR | __SRW)) == 0) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
        return (__sflush(fp));
diff --git a/src/system/libroot/posix/stdio/findfp.c 
b/src/system/libroot/posix/stdio/findfp.c
index bb6f555..0675ad1 100644
--- a/src/system/libroot/posix/stdio/findfp.c
+++ b/src/system/libroot/posix/stdio/findfp.c
@@ -41,6 +41,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <errno_private.h>
+
 #include "local.h"
 #include "glue.h"
 
@@ -55,7 +57,7 @@ int   __sdidinit;
  * must be cast to any desired pointer type.
  */
 #define ALIGNBYTES      (sizeof(int) - 1)
-#define ALIGN(p)        (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES) 
+#define ALIGN(p)        (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)
 
 #define        NDYNAMIC 10             /* add ten more whenever necessary */
 
diff --git a/src/system/libroot/posix/stdio/flags.c 
b/src/system/libroot/posix/stdio/flags.c
index 8550daf..e697c73 100644
--- a/src/system/libroot/posix/stdio/flags.c
+++ b/src/system/libroot/posix/stdio/flags.c
@@ -39,9 +39,10 @@
 //#include <sys/file.h>
 #include <stdio.h>
 #include <errno.h>
-
 #include <fcntl.h>
 
+#include <errno_private.h>
+
 #include "local.h"
 
 /*
@@ -77,7 +78,7 @@ __sflags(mode, optr)
                break;
 
        default:        /* illegal mode */
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return (0);
        }
 
diff --git a/src/system/libroot/posix/stdio/fopen.c 
b/src/system/libroot/posix/stdio/fopen.c
index 724b4c1..a8f58af 100644
--- a/src/system/libroot/posix/stdio/fopen.c
+++ b/src/system/libroot/posix/stdio/fopen.c
@@ -41,6 +41,8 @@
 #include <stdio.h>
 #include <errno.h>
 
+#include <errno_private.h>
+
 #include "local.h"
 
 FILE *
@@ -63,7 +65,7 @@ fopen(file, mode)
        if ((f = open(file, oflags, DEFFILEMODE)) < 0) {
                fp->_flags = 0;                 /* release */
 /* XXX - temporary hack */
-               errno = f;
+               __set_errno(f);
                return (NULL);
        }
        fp->_file = f;
diff --git a/src/system/libroot/posix/stdio/fputc.c 
b/src/system/libroot/posix/stdio/fputc.c
index 0565506..3dabbde 100644
--- a/src/system/libroot/posix/stdio/fputc.c
+++ b/src/system/libroot/posix/stdio/fputc.c
@@ -40,6 +40,9 @@ static char rcsid[] = "$OpenBSD: fputc.c,v 1.4 2001/07/09 
06:57:44 deraadt Exp $
 
 #include <stdio.h>
 #include <errno.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 int
@@ -48,7 +51,7 @@ fputc(c, fp)
        register FILE *fp;
 {
        if (cantwrite(fp)) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
        return (putc(c, fp));
diff --git a/src/system/libroot/posix/stdio/fseek.c 
b/src/system/libroot/posix/stdio/fseek.c
index 0dd712b..b3ffaeb 100644
--- a/src/system/libroot/posix/stdio/fseek.c
+++ b/src/system/libroot/posix/stdio/fseek.c
@@ -40,6 +40,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 #define        POS_ERR (-(fpos_t)1)
@@ -68,7 +71,7 @@ fseeko(fp, offset, whence)
         * Have to be able to seek.
         */
        if ((seekfn = fp->_seek) == NULL) {
-               errno = ESPIPE;                 /* historic practice */
+               __set_errno(ESPIPE);                    /* historic practice */
                return (EOF);
        }
 
@@ -111,7 +114,7 @@ fseeko(fp, offset, whence)
                break;
 
        default:
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return (EOF);
        }
 
diff --git a/src/system/libroot/posix/stdio/fvwrite.c 
b/src/system/libroot/posix/stdio/fvwrite.c
index f86744d..065d5f2 100644
--- a/src/system/libroot/posix/stdio/fvwrite.c
+++ b/src/system/libroot/posix/stdio/fvwrite.c
@@ -38,6 +38,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 #include "fvwrite.h"
 
@@ -64,7 +67,7 @@ __sfvwrite(fp, uio)
        }
        /* make sure we can write */
        if (cantwrite(fp)) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
 
diff --git a/src/system/libroot/posix/stdio/fwalk.c 
b/src/system/libroot/posix/stdio/fwalk.c
index 7d5ec39..cc1a04c 100644
--- a/src/system/libroot/posix/stdio/fwalk.c
+++ b/src/system/libroot/posix/stdio/fwalk.c
@@ -40,6 +40,9 @@ static char rcsid[] = "$OpenBSD: fwalk.c,v 1.3 2001/07/09 
06:57:44 deraadt Exp $
 
 #include <errno.h>
 #include <stdio.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 #include "glue.h"
 
diff --git a/src/system/libroot/posix/stdio/putc.c 
b/src/system/libroot/posix/stdio/putc.c
index 18d5a0a..b3a2da8 100644
--- a/src/system/libroot/posix/stdio/putc.c
+++ b/src/system/libroot/posix/stdio/putc.c
@@ -36,6 +36,9 @@
 
 #include <stdio.h>
 #include <errno.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 /*
@@ -51,7 +54,7 @@ putc_unlocked(c, fp)
        register FILE *fp;
 {
        if (cantwrite(fp)) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
        return (__sputc(c, fp));
diff --git a/src/system/libroot/posix/stdio/refill.c 
b/src/system/libroot/posix/stdio/refill.c
index e967ed7..c88fe84 100644
--- a/src/system/libroot/posix/stdio/refill.c
+++ b/src/system/libroot/posix/stdio/refill.c
@@ -38,6 +38,9 @@
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 static int
@@ -72,7 +75,7 @@ __srefill(fp)
        /* if not already reading, have to be reading and writing */
        if ((fp->_flags & __SRD) == 0) {
                if ((fp->_flags & __SRW) == 0) {
-                       errno = EBADF;
+                       __set_errno(EBADF);
                        fp->_flags |= __SERR;
                        return (EOF);
                }
diff --git a/src/system/libroot/posix/stdio/remove.c 
b/src/system/libroot/posix/stdio/remove.c
index e812065..856942d 100644
--- a/src/system/libroot/posix/stdio/remove.c
+++ b/src/system/libroot/posix/stdio/remove.c
@@ -8,6 +8,7 @@
 
 #include <errno.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -20,7 +21,7 @@ remove(const char* path)
                status = _kern_remove_dir(-1, path);
 
        if (status != B_OK) {
-               errno = status;
+               __set_errno(status);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/stdio/rename.c 
b/src/system/libroot/posix/stdio/rename.c
index 050e6a7..339af4d 100644
--- a/src/system/libroot/posix/stdio/rename.c
+++ b/src/system/libroot/posix/stdio/rename.c
@@ -1,4 +1,4 @@
-/* 
+/*
  * Copyright 2004-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx
  * Distributed under the terms of the MIT License.
  */
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <stdio.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
diff --git a/src/system/libroot/posix/stdio/rewind.c 
b/src/system/libroot/posix/stdio/rewind.c
index 1ed3c31..507718c 100644
--- a/src/system/libroot/posix/stdio/rewind.c
+++ b/src/system/libroot/posix/stdio/rewind.c
@@ -37,6 +37,8 @@
 #include <errno.h>
 #include <stdio.h>
 
+#include <errno_private.h>
+
 
 void
 rewind(fp)
@@ -44,5 +46,5 @@ rewind(fp)
 {
        (void) fseek(fp, 0L, SEEK_SET);
        //clearerr(fp);
-       errno = 0;      /* not required, but seems reasonable */
+       __set_errno(0);      /* not required, but seems reasonable */
 }
diff --git a/src/system/libroot/posix/stdio/vfprintf.c 
b/src/system/libroot/posix/stdio/vfprintf.c
index 31aa64b..e1d5024 100644
--- a/src/system/libroot/posix/stdio/vfprintf.c
+++ b/src/system/libroot/posix/stdio/vfprintf.c
@@ -53,8 +53,10 @@
 #      include <varargs.h>
 #endif
 
-#include "local.h"  
-#include "fvwrite.h"  
+#include <errno_private.h>
+
+#include "local.h"
+#include "fvwrite.h"
 
 static void __find_arguments (const char *fmt0, va_list ap,
        va_list **argtable);
@@ -254,7 +256,7 @@ vfprintf(FILE *fp, const char *fmt0, va_list ap)
            flags&LONGINT ? GETARG(u_long) : \
            flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
            (u_long)GETARG(u_int))
- 
+
          /*
           * Get * arguments, including the form *nn$.  Preserve the nextarg
           * that the argument can be gotten once the type is determined.
@@ -289,10 +291,10 @@ vfprintf(FILE *fp, const char *fmt0, va_list ap)
 #define GETARG(type) \
        (((argtable != NULL) ? (void)(ap = argtable[nextarg]) : (void)0), \
         nextarg++, va_arg(ap, type))
- 
+
        /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */
        if (cantwrite(fp)) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
 
@@ -412,7 +414,7 @@ reswitch:   switch (ch) {
                                        __find_arguments(fmt0, orgap,
                                            &argtable);
                                }
-                               goto rflag; 
+                               goto rflag;
                        }
                        width = n;
                        goto reswitch;
@@ -494,7 +496,7 @@ reswitch:   switch (ch) {
                                        ch = (ch == 'g') ? 'e' : 'E';
                                else
                                        ch = 'g';
-                       } 
+                       }
                        if (ch <= 'e') {        /* 'e' or 'E' fmt */
                                --expt;
                                expsize = exponent(expstr, expt, ch);
@@ -792,7 +794,7 @@ error:
  * table, indexed by argument number, of pointers to each arguments.  The
  * initial argument table should be an array of STATIC_ARG_TBL_SIZE entries.
  * It will be replaces with a malloc-ed on if it overflows.
- */ 
+ */
 
 static void
 __find_arguments(const char *fmt0, va_list ap, va_list **argtable)
@@ -847,7 +849,7 @@ __find_arguments(const char *fmt0, va_list ap, va_list 
**argtable)
        fmt = (char *)fmt0;
        typetable = stattypetable;
        tablesize = STATIC_ARG_TBL_SIZE;
-       tablemax = 0; 
+       tablemax = 0;
        nextarg = 1;
        memset(typetable, T_UNUSED, STATIC_ARG_TBL_SIZE);
 
@@ -1092,7 +1094,7 @@ __grow_type_table(unsigned char **typetable, int 
*tablesize)
        return(0);
 }
 
-  
+
 #ifdef FLOATING_POINT
 
 extern char *__dtoa __P((double, int, int, int *, int *, char **));
@@ -1106,8 +1108,8 @@ cvt(double value, int ndigits, int flags, char *sign, int 
*decpt, int ch, int *l
        if (ch == 'f') {
                mode = 3;               /* ndigits after the decimal point */
        } else {
-               /* To obtain ndigits after the decimal point for the 'e' 
-                * and 'E' formats, round to ndigits + 1 significant 
+               /* To obtain ndigits after the decimal point for the 'e'
+                * and 'E' formats, round to ndigits + 1 significant
                 * figures.
                 */
                if (ch == 'e' || ch == 'E') {
diff --git a/src/system/libroot/posix/stdio/wbuf.c 
b/src/system/libroot/posix/stdio/wbuf.c
index 1ad5bb6..5bdcb4f 100644
--- a/src/system/libroot/posix/stdio/wbuf.c
+++ b/src/system/libroot/posix/stdio/wbuf.c
@@ -36,6 +36,9 @@
 
 #include <stdio.h>
 #include <errno.h>
+
+#include <errno_private.h>
+
 #include "local.h"
 
 /*
@@ -59,7 +62,7 @@ __swbuf(c, fp)
         */
        fp->_w = fp->_lbfsize;
        if (cantwrite(fp)) {
-               errno = EBADF;
+               __set_errno(EBADF);
                return (EOF);
        }
        c = (unsigned char)c;
diff --git a/src/system/libroot/posix/stdlib/atfork.c 
b/src/system/libroot/posix/stdlib/atfork.c
index 66a699c..1ddc6ef 100644
--- a/src/system/libroot/posix/stdlib/atfork.c
+++ b/src/system/libroot/posix/stdlib/atfork.c
@@ -1,4 +1,4 @@
-/* 
+/*
 ** Copyright 2004, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx All rights reserved.
 ** Distributed under the terms of the Haiku License.
 */
@@ -9,6 +9,8 @@
 #include <stdlib.h>
 #include <errno.h>
 
+#include <errno_private.h>
+
 
 /**    This is the BeOS compatible atfork() function; since it's not part of 
POSIX,
  *     it should probably go away over time.
@@ -20,7 +22,7 @@ atfork(void (*function)(void))
 {
        status_t status = __register_atfork(NULL, NULL, function);
        if (status < B_OK) {
-               errno = status;
+               __set_errno(status);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/stdlib/env.cpp 
b/src/system/libroot/posix/stdlib/env.cpp
index a6c577d..d27a66f 100644
--- a/src/system/libroot/posix/stdlib/env.cpp
+++ b/src/system/libroot/posix/stdlib/env.cpp
@@ -11,6 +11,7 @@
 
 #include <OS.h>
 
+#include <errno_private.h>
 #include <libroot_private.h>
 #include <locks.h>
 #include <runtime_loader.h>
@@ -249,7 +250,7 @@ setenv(const char *name, const char *value, int overwrite)
        status_t status;
 
        if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return -1;
        }
 
@@ -268,7 +269,7 @@ unsetenv(const char *name)
        char *env;
 
        if (name == NULL || name[0] == '\0' || strchr(name, '=') != NULL) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return -1;
        }
 
@@ -285,8 +286,8 @@ unsetenv(const char *name)
                free(env);
                memmove(environ + index, environ + index + 1,
                        sizeof(char *) * (count_variables() - index));
-                       
-               // search possible another occurence, introduced via putenv() 
+
+               // search possible another occurence, introduced via putenv()
                // and renamed since
                env = find_variable(name, length, &index);
        }
@@ -303,7 +304,7 @@ putenv(const char *string)
        status_t status;
 
        if (value == NULL) {
-               errno = B_BAD_VALUE;
+               __set_errno(B_BAD_VALUE);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/stdlib/heapsort.c 
b/src/system/libroot/posix/stdlib/heapsort.c
index 02c7878..7b39361 100644
--- a/src/system/libroot/posix/stdlib/heapsort.c
+++ b/src/system/libroot/posix/stdlib/heapsort.c
@@ -41,6 +41,8 @@ static char sccsid[] = "@(#)heapsort.c        8.1 (Berkeley) 
6/4/93";
 #include <errno.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
 /*
  * Swap two areas of size number of bytes.  Although qsort(3) permits random
  * blocks of memory to be sorted, sorting pointers is almost certainly the
@@ -156,7 +158,7 @@ heapsort(void *vbase, size_t nmemb, size_t size, int 
(*compar)(void const *, voi
        }
 
        if (!size) {
-//             errno = EINVAL;
+//             __set_errno(EINVAL);
                return (-1);
        }
 
diff --git a/src/system/libroot/posix/stdlib/merge.c 
b/src/system/libroot/posix/stdlib/merge.c
index 17add08..2b60c1a 100644
--- a/src/system/libroot/posix/stdlib/merge.c
+++ b/src/system/libroot/posix/stdlib/merge.c
@@ -58,6 +58,8 @@ static char sccsid[] = "@(#)merge.c   8.2 (Berkeley) 2/14/94";
 #include <stdlib.h>
 #include <string.h>
 
+#include <errno_private.h>
+
 static void setup(u_char *, u_char *, size_t, size_t, int (*)());
 static void insertionsort(u_char *, size_t, size_t, int (*)());
 
@@ -116,7 +118,7 @@ mergesort(void *base, size_t nmemb, size_t size, int 
(*cmp)(void const *, void c
        u_char **p1;
 
        if (size < PSIZE / 2) {         /* Pointers must fit into 2 * size. */
-//             errno = EINVAL;
+//             __set_errno(EINVAL);
                return (-1);
        }
 
diff --git a/src/system/libroot/posix/stdlib/mktemp.c 
b/src/system/libroot/posix/stdlib/mktemp.c
index 870a292..1d1d999 100644
--- a/src/system/libroot/posix/stdlib/mktemp.c
+++ b/src/system/libroot/posix/stdlib/mktemp.c
@@ -42,6 +42,8 @@
 #include <unistd.h>
 #include <stdint.h>
 
+#include <errno_private.h>
+
 
 static int _gettemp(char *, int *, int, int);
 
@@ -96,7 +98,7 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
        int rval;
 
        if (doopen != NULL && domkdir) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return 0;
        }
 
@@ -107,7 +109,7 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
        suffp = trv;
        --trv;
        if (trv < path) {
-               errno = EINVAL;
+               __set_errno(EINVAL);
                return 0;
        }
 
@@ -130,7 +132,7 @@ _gettemp(char *path, int *doopen, int domkdir, int slen)
                                if (rval != 0)
                                        return 0;
                                if (!S_ISDIR(sbuf.st_mode)) {
-                                       errno = ENOTDIR;
+                                       __set_errno(ENOTDIR);
                                        return 0;
                                }
                                break;
diff --git a/src/system/libroot/posix/stdlib/radixsort.c 
b/src/system/libroot/posix/stdlib/radixsort.c
index 706fddc..d8f5d6d 100644
--- a/src/system/libroot/posix/stdlib/radixsort.c
+++ b/src/system/libroot/posix/stdlib/radixsort.c
@@ -55,6 +55,8 @@ static char sccsid[] = "@(#)radixsort.c       8.2 (Berkeley) 
4/28/95";
 #include <stdlib.h>
 #include <errno.h>
 
+#include <errno_private.h>
+
 typedef struct {
        const u_char **sa;
        int sn, si;
@@ -80,7 +82,7 @@ static void r_sort_b(u_char const **, u_char const **, int, 
int, u_char const *,
                endch = tab[endch];                                     \
                tr = tab;                                               \
                if (endch != 0 && endch != 255) {                       \
-                       /* errno = EINVAL; */                           \
+                       /* __set_errno(EINVAL); */                              
\
                        return (-1);                                    \
                }                                                       \
        }                                                               \
@@ -299,7 +301,7 @@ void
 simplesort(u_char const **a, int n, int b, u_char const *tr, u_int endch)      
/* insertion sort */
 {
        u_char ch;
-       u_char const **ak; 
+       u_char const **ak;
        u_char const **ai;
        u_char const  *s;
        u_char const  *t;
diff --git a/src/system/libroot/posix/stdlib/realpath.cpp 
b/src/system/libroot/posix/stdlib/realpath.cpp
index 5a5b70f..575198e 100644
--- a/src/system/libroot/posix/stdlib/realpath.cpp
+++ b/src/system/libroot/posix/stdlib/realpath.cpp
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <sys/stat.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -17,7 +18,7 @@ realpath(const char* path, char* resolved)
 {
        status_t status = _kern_normalize_path(path, true, resolved);
        if (status != B_OK) {
-               errno = status;
+               __set_errno(status);
                return NULL;
        }
 
diff --git a/src/system/libroot/posix/stdlib/strfmon.c 
b/src/system/libroot/posix/stdlib/strfmon.c
index 2e62624..25f0c30 100644
--- a/src/system/libroot/posix/stdlib/strfmon.c
+++ b/src/system/libroot/posix/stdlib/strfmon.c
@@ -36,6 +36,8 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include <errno_private.h>
+
 
 /* internal flags */
 #define        NEED_GROUPING           0x01    /* print digits grouped 
(default) */
@@ -384,11 +386,11 @@ strfmon(char *s, size_t maxsize, const char *format,
        return dst - s - 1;     /* return size of put data except trailing '\0' 
*/
 
 e2big_error:
-       errno = E2BIG;
+       __set_errno(E2BIG);
        goto end_error;
 
 format_error:
-       errno = EINVAL;
+       __set_errno(EINVAL);
 
 end_error:
        sverrno = errno;
@@ -396,7 +398,7 @@ end_error:
                free(asciivalue);
        if (currency_symbol != NULL)
                free(currency_symbol);
-       errno = sverrno;
+       __set_errno(sverrno);
        va_end(ap);
        return -1;
 }
diff --git a/src/system/libroot/posix/stdlib/strtod.c 
b/src/system/libroot/posix/stdlib/strtod.c
index d80c15a..9ff1b40 100644
--- a/src/system/libroot/posix/stdlib/strtod.c
+++ b/src/system/libroot/posix/stdlib/strtod.c
@@ -157,6 +157,8 @@ typedef     u_int32_t ULong;
 #include <errno.h>
 #include <ctype.h>
 
+#include <errno_private.h>
+
 #ifdef Bad_float_h
 #undef __STDC__
 #ifdef IEEE_BIG_ENDIAN
@@ -1306,7 +1308,7 @@ strtod(const char * __restrict s00, char ** __restrict se)
                if ( (e1 &= ~15) ) {
                        if (e1 > DBL_MAX_10_EXP) {
  ovfl:
-                               errno = ERANGE;
+                               __set_errno(ERANGE);
                                rv = HUGE_VAL;
                                goto ret;
                        }
@@ -1348,7 +1350,7 @@ strtod(const char * __restrict s00, char ** __restrict se)
                                if (!rv) {
  undfl:
                                        rv = 0.;
-                                       errno = ERANGE;
+                                       __set_errno(ERANGE);
                                        goto ret;
                                        }
                                word0(rv) = Tiny0;
diff --git a/src/system/libroot/posix/stdlib/strtol.c 
b/src/system/libroot/posix/stdlib/strtol.c
index fe88836..ba005fe 100644
--- a/src/system/libroot/posix/stdlib/strtol.c
+++ b/src/system/libroot/posix/stdlib/strtol.c
@@ -37,6 +37,8 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
 
 /*
  * Convert a string to a long integer.
@@ -125,10 +127,10 @@ strtol(const char * __restrict nptr, char ** __restrict 
endptr, int base)
        }
        if (any < 0) {
                acc = neg ? LONG_MIN : LONG_MAX;
-               errno = ERANGE;
+               __set_errno(ERANGE);
        } else if (!any) {
 noconv:
-               errno = EINVAL;
+               __set_errno(EINVAL);
        } else if (neg)
                acc = -acc;
        if (endptr != NULL)
diff --git a/src/system/libroot/posix/stdlib/strtoll.c 
b/src/system/libroot/posix/stdlib/strtoll.c
index 4771a12..59d5cd7 100644
--- a/src/system/libroot/posix/stdlib/strtoll.c
+++ b/src/system/libroot/posix/stdlib/strtoll.c
@@ -37,6 +37,8 @@
 #include <ctype.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
 
 /*
  * Convert a string to a long long integer.
@@ -126,10 +128,10 @@ strtoll(const char * __restrict nptr, char ** __restrict 
endptr, int base)
        }
        if (any < 0) {
                acc = neg ? LONGLONG_MIN : LONGLONG_MAX;
-               errno = ERANGE;
+               __set_errno(ERANGE);
        } else if (!any) {
 noconv:
-               errno = EINVAL;
+               __set_errno(EINVAL);
        } else if (neg)
                acc = -acc;
        if (endptr != NULL)
diff --git a/src/system/libroot/posix/stdlib/strtoq.c 
b/src/system/libroot/posix/stdlib/strtoq.c
index b15f809..075b6a3 100644
--- a/src/system/libroot/posix/stdlib/strtoq.c
+++ b/src/system/libroot/posix/stdlib/strtoq.c
@@ -38,6 +38,9 @@
 //#include <limits.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
+
 #define QUAD_MIN   (-0x7fffffffffffffffLL - 1)
 #define QUAD_MAX   0x7fffffffffffffffLL
 /*
@@ -126,7 +129,7 @@ strtoq(nptr, endptr, base)
                        if (acc < cutoff || (acc == cutoff && c > cutlim)) {
                                any = -1;
                                acc = QUAD_MIN;
-                               errno = ERANGE;
+                               __set_errno(ERANGE);
                        } else {
                                any = 1;
                                acc *= base;
@@ -136,7 +139,7 @@ strtoq(nptr, endptr, base)
                        if (acc > cutoff || (acc == cutoff && c > cutlim)) {
                                any = -1;
                                acc = QUAD_MAX;
-                               errno = ERANGE;
+                               __set_errno(ERANGE);
                        } else {
                                any = 1;
                                acc *= base;
diff --git a/src/system/libroot/posix/stdlib/strtoul.c 
b/src/system/libroot/posix/stdlib/strtoul.c
index 76f7c34..4194d8e 100644
--- a/src/system/libroot/posix/stdlib/strtoul.c
+++ b/src/system/libroot/posix/stdlib/strtoul.c
@@ -37,6 +37,8 @@
 #include <errno.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
 
 /*
  * Convert a string to an unsigned long integer.
@@ -104,10 +106,10 @@ strtoul(const char * __restrict nptr, char ** __restrict 
endptr, int base)
        }
        if (any < 0) {
                acc = ULONG_MAX;
-               errno = ERANGE;
+               __set_errno(ERANGE);
        } else if (!any) {
 noconv:
-               errno = EINVAL;
+               __set_errno(EINVAL);
        } else if (neg)
                acc = -acc;
        if (endptr != NULL)
diff --git a/src/system/libroot/posix/stdlib/strtoull.c 
b/src/system/libroot/posix/stdlib/strtoull.c
index 709dc2b..e36474d 100644
--- a/src/system/libroot/posix/stdlib/strtoull.c
+++ b/src/system/libroot/posix/stdlib/strtoull.c
@@ -37,6 +37,8 @@
 #include <ctype.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
 
 /*
  * Convert a string to an unsigned long long integer.
@@ -104,10 +106,10 @@ strtoull(const char * __restrict nptr, char ** __restrict 
endptr, int base)
        }
        if (any < 0) {
                acc = ULONGLONG_MAX;
-               errno = ERANGE;
+               __set_errno(ERANGE);
        } else if (!any) {
 noconv:
-               errno = EINVAL;
+               __set_errno(EINVAL);
        } else if (neg)
                acc = -acc;
        if (endptr != NULL)
diff --git a/src/system/libroot/posix/stdlib/strtouq.c 
b/src/system/libroot/posix/stdlib/strtouq.c
index 4d695ee..2dfce97 100644
--- a/src/system/libroot/posix/stdlib/strtouq.c
+++ b/src/system/libroot/posix/stdlib/strtouq.c
@@ -38,6 +38,9 @@
 //#include <limits.h>
 #include <stdlib.h>
 
+#include <errno_private.h>
+
+
 #define UQUAD_MAX 0xffffffffffffffffULL
 /*
  * Convert a string to an unsigned quad integer.
@@ -66,7 +69,7 @@ strtouq(nptr, endptr, base)
        if (c == '-') {
                neg = 1;
                c = *s++;
-       } else { 
+       } else {
                neg = 0;
                if (c == '+')
                        c = *s++;
@@ -96,7 +99,7 @@ strtouq(nptr, endptr, base)
                if (acc > cutoff || (acc == cutoff && c > cutlim)) {
                        any = -1;
                        acc = UQUAD_MAX;
-                       errno = ERANGE;
+                       __set_errno(ERANGE);
                } else {
                        any = 1;
                        acc *= (uint64)base;
diff --git a/src/system/libroot/posix/string/Jamfile 
b/src/system/libroot/posix/string/Jamfile
index a3d76e4..8fdbe7b 100644
--- a/src/system/libroot/posix/string/Jamfile
+++ b/src/system/libroot/posix/string/Jamfile
@@ -1,6 +1,9 @@
 SubDir HAIKU_TOP src system libroot posix string ;
 
-UsePrivateHeaders [ FDirName libroot locale ] ;
+UsePrivateHeaders 
+       [ FDirName libroot ] 
+       [ FDirName libroot locale ] 
+;
 
 MergeObject posix_string.o :
        bcmp.c
diff --git a/src/system/libroot/posix/string/strcoll.cpp 
b/src/system/libroot/posix/string/strcoll.cpp
index 5c1aa1f..1a477e5 100644
--- a/src/system/libroot/posix/string/strcoll.cpp
+++ b/src/system/libroot/posix/string/strcoll.cpp
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include <errno_private.h>
 #include "LocaleBackend.h"
 
 
@@ -21,7 +22,7 @@ strcoll(const char *a, const char *b)
                status_t status = gLocaleBackend->Strcoll(a, b, result);
 
                if (status != B_OK)
-                       errno = EINVAL;
+                       __set_errno(EINVAL);
 
                return result;
        }
diff --git a/src/system/libroot/posix/string/strxfrm.cpp 
b/src/system/libroot/posix/string/strxfrm.cpp
index e3b21bd..058f3cf 100644
--- a/src/system/libroot/posix/string/strxfrm.cpp
+++ b/src/system/libroot/posix/string/strxfrm.cpp
@@ -7,6 +7,7 @@
 #include <errno.h>
 #include <string.h>
 
+#include <errno_private.h>
 #include "LocaleBackend.h"
 
 
@@ -21,7 +22,7 @@ strxfrm(char *out, const char *in, size_t size)
                status_t status =  gLocaleBackend->Strxfrm(out, in, size, 
outSize);
 
                if (status != B_OK)
-                       errno = EINVAL;
+                       __set_errno(EINVAL);
 
                return outSize;
        }
diff --git a/src/system/libroot/posix/sys/chmod.c 
b/src/system/libroot/posix/sys/chmod.c
index 9f36ef5..95305e4 100644
--- a/src/system/libroot/posix/sys/chmod.c
+++ b/src/system/libroot/posix/sys/chmod.c
@@ -9,6 +9,7 @@
 
 #include <NodeMonitor.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 #include <syscall_utils.h>
 
diff --git a/src/system/libroot/posix/sys/flock.c 
b/src/system/libroot/posix/sys/flock.c
index 3967c11..728cf6d 100644
--- a/src/system/libroot/posix/sys/flock.c
+++ b/src/system/libroot/posix/sys/flock.c
@@ -9,6 +9,7 @@
 #include <errno.h>
 #include <pthread.h>
 
+#include <errno_private.h>
 #include <syscalls.h>
 
 
@@ -20,7 +21,7 @@ flock(int fd, int op)
        pthread_testcancel();
 
        if (status < B_OK) {
-               errno = status;
+               __set_errno(status);
                return -1;
        }
 
diff --git a/src/system/libroot/posix/sys/getrusage.c 
b/src/system/libroot/posix/sys/getrusage.c
index 4f3bc0a..df56ece 100644
--- a/src/system/libroot/posix/sys/getrusage.c
+++ b/src/system/libroot/posix/sys/getrusage.c
@@ -8,6 +8,8 @@
 #include <sys/resource.h>
 #include <errno.h>
 

[ *** diff truncated: 1568 lines dropped *** ]


############################################################################

Commit:      59e43b2ac9a219126b6ff3cf522905b546872d86
URL:         http://cgit.haiku-os.org/haiku/commit/?id=59e43b2
Author:      Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
Date:        Thu Nov 24 22:41:43 2011 UTC

Add tracing to some locale backend functions.

----------------------------------------------------------------------------

############################################################################

Revision:    hrev43317
Commit:      8fd51c08197d5acd9ff3c63aaed4772512bb8310
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8fd51c0
Author:      Oliver Tappe <zooey@xxxxxxxxxxxxxxx>
Date:        Thu Nov 24 22:47:27 2011 UTC

Use ErrnoMaintainer in setlocale() to protect errno.

* this avoids spurious errno changes leaking into application code,
  which could become confused - i.e. 'rm' on a gcc4 build would always
  prompt for confirmation

I spend a couple of hours hunting down the behavioural difference
between gcc2- and gcc4-builds and it turns out that the reason for that
is that gcc4's libstdc++-code initializes its own locale data via the
POSIX calls, which trigger (correct) errno value changes, which were the
ones leaking into application code.

----------------------------------------------------------------------------


Other related posts:

  • » [haiku-commits] haiku: hrev43317 - in src/system/libroot/posix: . unistd stdlib stdio sys - zooey