From ae9019359606f1db67632ef51a77ce70001d3770 Mon Sep 17 00:00:00 2001 From: Oliver Tappe Date: Thu, 24 Nov 2011 23:40:10 +0100 Subject: [PATCH] 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 --- headers/private/libroot/errno_private.h | 28 ++++++++ src/libs/stdc++/legacy/Jamfile | 2 + .../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 + .../libroot/posix/glibc/arch/m68k/Jamfile | 2 + .../libroot/posix/glibc/arch/ppc/Jamfile | 2 + .../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 + .../libroot/posix/glibc/libio/fileops.c | 6 -- .../libroot/posix/glibc/libio/ioseekoff.c | 6 -- src/system/libroot/posix/glibc/libio/libioP.h | 3 - .../libroot/posix/glibc/libio/oldfileops.c | 6 -- src/system/libroot/posix/glibc/misc/Jamfile | 3 + .../libroot/posix/glibc/stdio-common/Jamfile | 3 +- .../posix/glibc/stdio-common/tempname.c | 3 - .../posix/glibc/stdio-common/vfscanf.c | 4 +- src/system/libroot/posix/glibc/stdlib/Jamfile | 2 + .../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/wctype.cpp | 6 +- src/system/libroot/posix/malloc/wrapper.cpp | 11 +-- src/system/libroot/posix/malloc_debug/Jamfile | 2 +- .../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 + .../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 +- .../libroot/posix/signal/sigpending.cpp | 1 + src/system/libroot/posix/signal/sigqueue.cpp | 1 + .../libroot/posix/signal/sigset_accessors.cpp | 13 ++-- .../libroot/posix/signal/sigsuspend.cpp | 3 +- .../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 +- src/system/libroot/posix/sys/select.c | 1 + src/system/libroot/posix/sys/stat.c | 1 + src/system/libroot/posix/sys/times.cpp | 5 +- src/system/libroot/posix/sys/uio.c | 8 ++- src/system/libroot/posix/sys/umask.c | 1 + src/system/libroot/posix/sys/uname.c | 3 +- src/system/libroot/posix/sys/utimes.c | 1 + src/system/libroot/posix/sys/wait.cpp | 1 + .../libroot/posix/sys/xsi_msg_queue.cpp | 1 + src/system/libroot/posix/sys/xsi_sem.cpp | 1 + src/system/libroot/posix/termios.c | 12 ++-- .../libroot/posix/time/clock_support.cpp | 1 + src/system/libroot/posix/time/localtime.cpp | 19 ++--- src/system/libroot/posix/time/nanosleep.c | 1 + src/system/libroot/posix/time/stime.c | 6 +- src/system/libroot/posix/time/strptime.c | 8 ++- .../libroot/posix/time/timer_support.cpp | 1 + src/system/libroot/posix/time/wcsftime.c | 6 +- src/system/libroot/posix/unistd/access.c | 3 +- src/system/libroot/posix/unistd/alarm.c | 1 + src/system/libroot/posix/unistd/chown.c | 1 + src/system/libroot/posix/unistd/chroot.cpp | 4 +- src/system/libroot/posix/unistd/close.c | 1 + src/system/libroot/posix/unistd/conf.cpp | 27 +++---- src/system/libroot/posix/unistd/directory.c | 9 +-- src/system/libroot/posix/unistd/dup.c | 1 + src/system/libroot/posix/unistd/exec.cpp | 20 +++--- src/system/libroot/posix/unistd/fork.c | 3 +- src/system/libroot/posix/unistd/getlogin.c | 4 +- src/system/libroot/posix/unistd/hostname.cpp | 6 +- src/system/libroot/posix/unistd/ioctl.c | 6 +- src/system/libroot/posix/unistd/link.c | 3 +- src/system/libroot/posix/unistd/lockf.cpp | 6 +- src/system/libroot/posix/unistd/lseek.c | 5 +- src/system/libroot/posix/unistd/mknod.c | 8 ++- src/system/libroot/posix/unistd/mount.c | 13 ++-- src/system/libroot/posix/unistd/pause.c | 4 +- src/system/libroot/posix/unistd/pipe.c | 5 +- src/system/libroot/posix/unistd/process.c | 14 ++-- src/system/libroot/posix/unistd/read.c | 1 + src/system/libroot/posix/unistd/sbrk.c | 2 + src/system/libroot/posix/unistd/sync.c | 3 +- src/system/libroot/posix/unistd/system.cpp | 2 +- src/system/libroot/posix/unistd/truncate.c | 4 +- src/system/libroot/posix/unistd/ttyname.c | 7 +- src/system/libroot/posix/unistd/ualarm.c | 1 + src/system/libroot/posix/unistd/usergroup.cpp | 6 +- src/system/libroot/posix/unistd/usleep.c | 7 +- src/system/libroot/posix/unistd/write.c | 1 + .../libroot/posix/user_group_common.cpp | 1 + src/system/libroot/posix/utime.c | 3 +- src/system/libroot/posix/wchar/mbrtowc.cpp | 7 +- src/system/libroot/posix/wchar/mbtowc.c | 3 +- src/system/libroot/posix/wchar/wcrtomb.cpp | 9 ++- 150 files changed, 520 insertions(+), 301 deletions(-) create mode 100644 headers/private/libroot/errno_private.h diff --git a/headers/private/libroot/errno_private.h b/headers/private/libroot/errno_private.h new file mode 100644 index 0000000000..eb776e1596 --- /dev/null +++ b/headers/private/libroot/errno_private.h @@ -0,0 +1,28 @@ +/* + * Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. + * Distributed under the terms of the MIT License. + */ +#ifndef _ERRNO_PRIVATE_H +#define _ERRNO_PRIVATE_H + + +#include + +//#define TRACE_ERRNO + +#if defined(TRACE_ERRNO) && !defined(_KERNEL_MODE) +# include +# 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 2db2e5e76f..516d688430 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 9e47b55e82..6ba9fec106 100644 --- a/src/system/libroot/os/arch/x86/compatibility.c +++ b/src/system/libroot/os/arch/x86/compatibility.c @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -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 a324dc8df2..830beb50d3 100644 --- a/src/system/libroot/os/find_directory.cpp +++ b/src/system/libroot/os/find_directory.cpp @@ -24,6 +24,7 @@ #include #include +#include #include /* 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 7e906066fc..fecfdd0773 100644 --- a/src/system/libroot/os/fs_attr.cpp +++ b/src/system/libroot/os/fs_attr.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -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 2fe30cccc3..89469e2aa1 100644 --- a/src/system/libroot/os/fs_index.c +++ b/src/system/libroot/os/fs_index.c @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -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 eda4b1bbb2..d9bb11d158 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@pinc-software.de. All rights reserved. ** Distributed under the terms of the Haiku License. */ @@ -10,13 +10,14 @@ #include #include +#include #include #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 781ae67e98..3feac4462f 100644 --- a/src/system/libroot/os/fs_query.cpp +++ b/src/system/libroot/os/fs_query.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -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 3c8810feb3..19d29536a5 100644 --- a/src/system/libroot/os/time.cpp +++ b/src/system/libroot/os/time.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include diff --git a/src/system/libroot/posix/dirent.c b/src/system/libroot/posix/dirent.c index fef3e3b9b8..09f5f5f8c4 100644 --- a/src/system/libroot/posix/dirent.c +++ b/src/system/libroot/posix/dirent.c @@ -13,6 +13,7 @@ #include #include +#include #include #include @@ -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 1e0608b8f4..2f99596145 100644 --- a/src/system/libroot/posix/fcntl.cpp +++ b/src/system/libroot/posix/fcntl.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include diff --git a/src/system/libroot/posix/glibc/arch/m68k/Jamfile b/src/system/libroot/posix/glibc/arch/m68k/Jamfile index d93cba6af2..4686573da6 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 44ad8c5fc5..a01f1a5545 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 0630d602ea..ebd9e30afc 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 8689bcaccf..01be0be6ee 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 30938a779c..28f0a547cd 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 -#define __set_errno(val) errno = (val) +#include diff --git a/src/system/libroot/posix/glibc/libio/Jamfile b/src/system/libroot/posix/glibc/libio/Jamfile index 2e10d5ae7d..ca7e0d1ec4 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 ad75784c37..cdae3138d5 100644 --- a/src/system/libroot/posix/glibc/libio/fileops.c +++ b/src/system/libroot/posix/glibc/libio/fileops.c @@ -50,12 +50,6 @@ # include #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 fe3f57e74e..154a343ced 100644 --- a/src/system/libroot/posix/glibc/libio/ioseekoff.c +++ b/src/system/libroot/posix/glibc/libio/ioseekoff.c @@ -28,12 +28,6 @@ #include #include #include -#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 4c808e4184..cb1a48ac29 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 -#ifndef __set_errno -# define __set_errno(Val) errno = (Val) -#endif #if defined __GLIBC__ && __GLIBC__ >= 2 # include #else diff --git a/src/system/libroot/posix/glibc/libio/oldfileops.c b/src/system/libroot/posix/glibc/libio/oldfileops.c index cb1bb2e15d..3e22c836c6 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 #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 0dcf7afccc..52767e5cbd 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 b13bad0384..bea6ede166 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 e46376052f..902dc4ba94 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 #include -#ifndef __set_errno -# define __set_errno(Val) errno = (Val) -#endif #include #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 41504c8a9e..10d09a9c5c 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 acf6be776c..35b07cc6b1 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 d2e09c8404..eb8602f637 100644 --- a/src/system/libroot/posix/glibc/stdlib/strtol.c +++ b/src/system/libroot/posix/glibc/stdlib/strtol.c @@ -29,12 +29,6 @@ #include #include -#ifndef errno -extern int errno; -#endif -#ifndef __set_errno -# define __set_errno(Val) errno = (Val) -#endif #ifdef HAVE_LIMITS_H # include @@ -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 b8c4768c2c..b2ed36c780 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 397a40c4a1..83365ee522 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 #include +#include + #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 e28db529f6..f8faac4f7c 100644 --- a/src/system/libroot/posix/grp.cpp +++ b/src/system/libroot/posix/grp.cpp @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -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 f65b3349a0..1d96bba252 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 05df504802..248079c91c 100644 --- a/src/system/libroot/posix/locale/wctype.cpp +++ b/src/system/libroot/posix/locale/wctype.cpp @@ -8,6 +8,8 @@ #include #include +#include + #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 5741107cd9..2af067fa5b 100644 --- a/src/system/libroot/posix/malloc/wrapper.cpp +++ b/src/system/libroot/posix/malloc/wrapper.cpp @@ -29,6 +29,7 @@ #include #include +#include #include #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 4def90d325..53c2d86fc9 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 c3a5097335..0753f674ec 100644 --- a/src/system/libroot/posix/malloc_debug/heap.cpp +++ b/src/system/libroot/posix/malloc_debug/heap.cpp @@ -19,6 +19,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/poll.c b/src/system/libroot/posix/poll.c index 7898059296..cbd0f37c2c 100644 --- a/src/system/libroot/posix/poll.c +++ b/src/system/libroot/posix/poll.c @@ -11,6 +11,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/pwd.cpp b/src/system/libroot/posix/pwd.cpp index aa4ac55a60..57839baa56 100644 --- a/src/system/libroot/posix/pwd.cpp +++ b/src/system/libroot/posix/pwd.cpp @@ -13,6 +13,7 @@ #include +#include #include #include #include @@ -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 735d0e8627..1fe7f57a53 100644 --- a/src/system/libroot/posix/pwd_query.c +++ b/src/system/libroot/posix/pwd_query.c @@ -20,7 +20,9 @@ #include #include -/* +#include + +/* * 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 95799b6c04..f56543d023 100644 --- a/src/system/libroot/posix/scheduler.cpp +++ b/src/system/libroot/posix/scheduler.cpp @@ -10,6 +10,7 @@ #include +#include #include @@ -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 95647835c7..b96b8358f7 100644 --- a/src/system/libroot/posix/semaphore.cpp +++ b/src/system/libroot/posix/semaphore.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -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 999f6b3cd9..5f3d32b994 100644 --- a/src/system/libroot/posix/shadow.cpp +++ b/src/system/libroot/posix/shadow.cpp @@ -14,6 +14,7 @@ #include #include +#include #include #include #include @@ -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 ed01a3949f..999366a23a 100644 --- a/src/system/libroot/posix/signal/kill.c +++ b/src/system/libroot/posix/signal/kill.c @@ -9,6 +9,7 @@ #include +#include #include @@ -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 ef00d7239f..0ee8e644b0 100644 --- a/src/system/libroot/posix/signal/killpg.cpp +++ b/src/system/libroot/posix/signal/killpg.cpp @@ -7,6 +7,8 @@ #include #include +#include + 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 9696693a01..6f3e1e7969 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 #include +#include #include diff --git a/src/system/libroot/posix/signal/set_signal_stack.c b/src/system/libroot/posix/signal/set_signal_stack.c index 84e048116b..89b547d898 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 +#include #include @@ -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 8025ff4f55..f8dea2ec74 100644 --- a/src/system/libroot/posix/signal/sigaction.cpp +++ b/src/system/libroot/posix/signal/sigaction.cpp @@ -17,6 +17,7 @@ #include #include +#include #include diff --git a/src/system/libroot/posix/signal/sigaltstack.c b/src/system/libroot/posix/signal/sigaltstack.c index d191a16bc1..07d62e36aa 100644 --- a/src/system/libroot/posix/signal/sigaltstack.c +++ b/src/system/libroot/posix/signal/sigaltstack.c @@ -7,6 +7,7 @@ #include #include +#include #include @@ -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 8f3495f139..e99c51c9b5 100644 --- a/src/system/libroot/posix/signal/signal.cpp +++ b/src/system/libroot/posix/signal/signal.cpp @@ -15,6 +15,7 @@ #include +#include #include @@ -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 24d6288d08..b923a3258a 100644 --- a/src/system/libroot/posix/signal/sigpending.cpp +++ b/src/system/libroot/posix/signal/sigpending.cpp @@ -14,6 +14,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/signal/sigqueue.cpp b/src/system/libroot/posix/signal/sigqueue.cpp index 129e29cf21..8ad1a1ff38 100644 --- a/src/system/libroot/posix/signal/sigqueue.cpp +++ b/src/system/libroot/posix/signal/sigqueue.cpp @@ -10,6 +10,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/signal/sigset_accessors.cpp b/src/system/libroot/posix/signal/sigset_accessors.cpp index cf304b6c25..6b630b778d 100644 --- a/src/system/libroot/posix/signal/sigset_accessors.cpp +++ b/src/system/libroot/posix/signal/sigset_accessors.cpp @@ -17,6 +17,7 @@ #include +#include #include @@ -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 5b9a1c57af..21fc684305 100644 --- a/src/system/libroot/posix/signal/sigsuspend.cpp +++ b/src/system/libroot/posix/signal/sigsuspend.cpp @@ -18,6 +18,7 @@ #include #include +#include #include @@ -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 1ae8382bbd..7e1878748f 100644 --- a/src/system/libroot/posix/signal/sigtimedwait.cpp +++ b/src/system/libroot/posix/signal/sigtimedwait.cpp @@ -11,6 +11,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/signal/strsignal.cpp b/src/system/libroot/posix/signal/strsignal.cpp index 3ba17f9583..7a92a41415 100644 --- a/src/system/libroot/posix/signal/strsignal.cpp +++ b/src/system/libroot/posix/signal/strsignal.cpp @@ -14,6 +14,7 @@ #include #include +#include #include diff --git a/src/system/libroot/posix/stdio/fclose.c b/src/system/libroot/posix/stdio/fclose.c index b2a0567ec1..23d1819c08 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 #include #include + +#include + #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 e2fe1bfd10..5becca3f7a 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 #include + +#include + #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 bb6f55596e..0675ad1172 100644 --- a/src/system/libroot/posix/stdio/findfp.c +++ b/src/system/libroot/posix/stdio/findfp.c @@ -41,6 +41,8 @@ #include #include +#include + #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 8550daf875..e697c730e6 100644 --- a/src/system/libroot/posix/stdio/flags.c +++ b/src/system/libroot/posix/stdio/flags.c @@ -39,9 +39,10 @@ //#include #include #include - #include +#include + #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 724b4c1ae9..a8f58af6bf 100644 --- a/src/system/libroot/posix/stdio/fopen.c +++ b/src/system/libroot/posix/stdio/fopen.c @@ -41,6 +41,8 @@ #include #include +#include + #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 056550637c..3dabbde606 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 #include + +#include + #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 0dd712b71e..b3ffaeb150 100644 --- a/src/system/libroot/posix/stdio/fseek.c +++ b/src/system/libroot/posix/stdio/fseek.c @@ -40,6 +40,9 @@ #include #include #include + +#include + #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 f86744d6ee..065d5f2e63 100644 --- a/src/system/libroot/posix/stdio/fvwrite.c +++ b/src/system/libroot/posix/stdio/fvwrite.c @@ -38,6 +38,9 @@ #include #include #include + +#include + #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 7d5ec390cf..cc1a04c5cf 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 #include + +#include + #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 18d5a0ab75..b3a2da8c26 100644 --- a/src/system/libroot/posix/stdio/putc.c +++ b/src/system/libroot/posix/stdio/putc.c @@ -36,6 +36,9 @@ #include #include + +#include + #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 e967ed7e98..c88fe842ed 100644 --- a/src/system/libroot/posix/stdio/refill.c +++ b/src/system/libroot/posix/stdio/refill.c @@ -38,6 +38,9 @@ #include #include #include + +#include + #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 e8120650af..856942d6fd 100644 --- a/src/system/libroot/posix/stdio/remove.c +++ b/src/system/libroot/posix/stdio/remove.c @@ -8,6 +8,7 @@ #include +#include #include @@ -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 050e6a7177..339af4de30 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@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/stdio/rewind.c b/src/system/libroot/posix/stdio/rewind.c index 1ed3c3188a..507718c25a 100644 --- a/src/system/libroot/posix/stdio/rewind.c +++ b/src/system/libroot/posix/stdio/rewind.c @@ -37,6 +37,8 @@ #include #include +#include + 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 31aa64b935..e1d5024192 100644 --- a/src/system/libroot/posix/stdio/vfprintf.c +++ b/src/system/libroot/posix/stdio/vfprintf.c @@ -53,8 +53,10 @@ # include #endif -#include "local.h" -#include "fvwrite.h" +#include + +#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 1ad5bb633b..5bdcb4f46f 100644 --- a/src/system/libroot/posix/stdio/wbuf.c +++ b/src/system/libroot/posix/stdio/wbuf.c @@ -36,6 +36,9 @@ #include #include + +#include + #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 66a699c8a2..1ddc6eff10 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@pinc-software.de. All rights reserved. ** Distributed under the terms of the Haiku License. */ @@ -9,6 +9,8 @@ #include #include +#include + /** 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 a6c577dd6b..d27a66fdf8 100644 --- a/src/system/libroot/posix/stdlib/env.cpp +++ b/src/system/libroot/posix/stdlib/env.cpp @@ -11,6 +11,7 @@ #include +#include #include #include #include @@ -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 02c7878e88..7b39361497 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 #include +#include + /* * 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 17add08968..2b60c1a0a5 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 #include +#include + 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 870a292df5..1d1d9991b4 100644 --- a/src/system/libroot/posix/stdlib/mktemp.c +++ b/src/system/libroot/posix/stdlib/mktemp.c @@ -42,6 +42,8 @@ #include #include +#include + 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 706fddcec9..d8f5d6dbc7 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 #include +#include + 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 5a5b70fd6c..575198ec80 100644 --- a/src/system/libroot/posix/stdlib/realpath.cpp +++ b/src/system/libroot/posix/stdlib/realpath.cpp @@ -9,6 +9,7 @@ #include #include +#include #include @@ -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 2e62624392..25f0c30c9c 100644 --- a/src/system/libroot/posix/stdlib/strfmon.c +++ b/src/system/libroot/posix/stdlib/strfmon.c @@ -36,6 +36,8 @@ #include #include +#include + /* 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 d80c15a39a..9ff1b400f6 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 #include +#include + #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 fe8883673f..ba005fee0d 100644 --- a/src/system/libroot/posix/stdlib/strtol.c +++ b/src/system/libroot/posix/stdlib/strtol.c @@ -37,6 +37,8 @@ #include #include +#include + /* * 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 4771a122ff..59d5cd72f8 100644 --- a/src/system/libroot/posix/stdlib/strtoll.c +++ b/src/system/libroot/posix/stdlib/strtoll.c @@ -37,6 +37,8 @@ #include #include +#include + /* * 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 b15f8090a4..075b6a3b95 100644 --- a/src/system/libroot/posix/stdlib/strtoq.c +++ b/src/system/libroot/posix/stdlib/strtoq.c @@ -38,6 +38,9 @@ //#include #include +#include + + #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 76f7c349c3..4194d8e71d 100644 --- a/src/system/libroot/posix/stdlib/strtoul.c +++ b/src/system/libroot/posix/stdlib/strtoul.c @@ -37,6 +37,8 @@ #include #include +#include + /* * 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 709dc2bb76..e36474d8ea 100644 --- a/src/system/libroot/posix/stdlib/strtoull.c +++ b/src/system/libroot/posix/stdlib/strtoull.c @@ -37,6 +37,8 @@ #include #include +#include + /* * 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 4d695eefef..2dfce976b5 100644 --- a/src/system/libroot/posix/stdlib/strtouq.c +++ b/src/system/libroot/posix/stdlib/strtouq.c @@ -38,6 +38,9 @@ //#include #include +#include + + #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 a3d76e4811..8fdbe7b538 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 5c1aa1fb14..1a477e57f0 100644 --- a/src/system/libroot/posix/string/strcoll.cpp +++ b/src/system/libroot/posix/string/strcoll.cpp @@ -7,6 +7,7 @@ #include #include +#include #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 e3b21bdf86..058f3cf123 100644 --- a/src/system/libroot/posix/string/strxfrm.cpp +++ b/src/system/libroot/posix/string/strxfrm.cpp @@ -7,6 +7,7 @@ #include #include +#include #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 9f36ef5971..95305e48b1 100644 --- a/src/system/libroot/posix/sys/chmod.c +++ b/src/system/libroot/posix/sys/chmod.c @@ -9,6 +9,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/flock.c b/src/system/libroot/posix/sys/flock.c index 3967c115b0..728cf6de24 100644 --- a/src/system/libroot/posix/sys/flock.c +++ b/src/system/libroot/posix/sys/flock.c @@ -9,6 +9,7 @@ #include #include +#include #include @@ -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 4f3bc0af51..df56ece99a 100644 --- a/src/system/libroot/posix/sys/getrusage.c +++ b/src/system/libroot/posix/sys/getrusage.c @@ -8,6 +8,8 @@ #include #include +#include + int getrusage(int who, struct rusage *rusage) @@ -15,7 +17,7 @@ getrusage(int who, struct rusage *rusage) team_usage_info info; if (get_team_usage_info(B_CURRENT_TEAM, who, &info) != B_OK) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } diff --git a/src/system/libroot/posix/sys/itimer.cpp b/src/system/libroot/posix/sys/itimer.cpp index fe47269579..42a7b72e24 100644 --- a/src/system/libroot/posix/sys/itimer.cpp +++ b/src/system/libroot/posix/sys/itimer.cpp @@ -13,6 +13,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/mkdir.c b/src/system/libroot/posix/sys/mkdir.c index 4b5994da3d..5731968910 100644 --- a/src/system/libroot/posix/sys/mkdir.c +++ b/src/system/libroot/posix/sys/mkdir.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/src/system/libroot/posix/sys/mkfifo.c b/src/system/libroot/posix/sys/mkfifo.c index e18a111f26..62fd7a34e0 100644 --- a/src/system/libroot/posix/sys/mkfifo.c +++ b/src/system/libroot/posix/sys/mkfifo.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/sys/mman.cpp b/src/system/libroot/posix/sys/mman.cpp index 28886e5e1b..a936840742 100644 --- a/src/system/libroot/posix/sys/mman.cpp +++ b/src/system/libroot/posix/sys/mman.cpp @@ -12,6 +12,7 @@ #include +#include #include #include #include @@ -90,7 +91,7 @@ mmap(void* address, size_t length, int protection, int flags, int fd, { // offset and length must be page-aligned if (length == 0 || offset % B_PAGE_SIZE != 0) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return MAP_FAILED; } @@ -98,13 +99,13 @@ mmap(void* address, size_t length, int protection, int flags, int fd, if ((flags & MAP_ANONYMOUS) != 0) { fd = -1; } else if (fd < 0) { - errno = EBADF; + __set_errno(EBADF); return MAP_FAILED; } // either MAP_SHARED or MAP_PRIVATE must be specified if (((flags & MAP_SHARED) != 0) == ((flags & MAP_PRIVATE) != 0)) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return MAP_FAILED; } @@ -128,7 +129,7 @@ mmap(void* address, size_t length, int protection, int flags, int fd, area_id area = _kern_map_file("mmap area", &address, addressSpec, length, areaProtection, mapping, true, fd, offset); if (area < 0) { - errno = area; + __set_errno(area); return MAP_FAILED; } diff --git a/src/system/libroot/posix/sys/rlimit.c b/src/system/libroot/posix/sys/rlimit.c index d759e39775..a5a94dc05f 100644 --- a/src/system/libroot/posix/sys/rlimit.c +++ b/src/system/libroot/posix/sys/rlimit.c @@ -8,10 +8,12 @@ #include #include +#include + #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; diff --git a/src/system/libroot/posix/sys/select.c b/src/system/libroot/posix/sys/select.c index d0549d9176..96948cebf2 100644 --- a/src/system/libroot/posix/sys/select.c +++ b/src/system/libroot/posix/sys/select.c @@ -12,6 +12,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/stat.c b/src/system/libroot/posix/sys/stat.c index af8530d1fa..2fc29662d4 100644 --- a/src/system/libroot/posix/sys/stat.c +++ b/src/system/libroot/posix/sys/stat.c @@ -10,6 +10,7 @@ #include +#include #include #include #include diff --git a/src/system/libroot/posix/sys/times.cpp b/src/system/libroot/posix/sys/times.cpp index 50d3cc5b20..54e3f11dde 100644 --- a/src/system/libroot/posix/sys/times.cpp +++ b/src/system/libroot/posix/sys/times.cpp @@ -12,6 +12,7 @@ #include +#include #include #include @@ -24,7 +25,7 @@ times_common(struct tms* buffer, bigtime_t microSecondsPerClock) if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_SELF, &info)) != B_OK) { - errno = err; + __set_errno(err); return -1; } @@ -33,7 +34,7 @@ times_common(struct tms* buffer, bigtime_t microSecondsPerClock) if ((err = get_team_usage_info(B_CURRENT_TEAM, RUSAGE_CHILDREN, &info)) != B_OK) { - errno = err; + __set_errno(err); return -1; } diff --git a/src/system/libroot/posix/sys/uio.c b/src/system/libroot/posix/sys/uio.c index 2d58ef1fbc..3f71b4c286 100644 --- a/src/system/libroot/posix/sys/uio.c +++ b/src/system/libroot/posix/sys/uio.c @@ -9,10 +9,12 @@ #include #include +#include + #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; @@ -32,7 +34,7 @@ readv_pos(int fd, off_t pos, const struct iovec *vecs, size_t count) { ssize_t bytes; if (pos < 0) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } bytes = _kern_readv(fd, pos, vecs, count); @@ -55,7 +57,7 @@ writev_pos(int fd, off_t pos, const struct iovec *vecs, size_t count) { ssize_t bytes; if (pos < 0) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } bytes = _kern_writev(fd, pos, vecs, count); diff --git a/src/system/libroot/posix/sys/umask.c b/src/system/libroot/posix/sys/umask.c index 69039fee1c..0ec1d299e3 100644 --- a/src/system/libroot/posix/sys/umask.c +++ b/src/system/libroot/posix/sys/umask.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/sys/uname.c b/src/system/libroot/posix/sys/uname.c index 3ff360888d..717f009fd0 100644 --- a/src/system/libroot/posix/sys/uname.c +++ b/src/system/libroot/posix/sys/uname.c @@ -13,6 +13,7 @@ #include +#include #include @@ -24,7 +25,7 @@ uname(struct utsname *info) const char *haikuRevision; if (!info) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } diff --git a/src/system/libroot/posix/sys/utimes.c b/src/system/libroot/posix/sys/utimes.c index 3dc7c473c9..3f1d06480d 100644 --- a/src/system/libroot/posix/sys/utimes.c +++ b/src/system/libroot/posix/sys/utimes.c @@ -11,6 +11,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/wait.cpp b/src/system/libroot/posix/sys/wait.cpp index ce4beedf9f..1c785c9fdb 100644 --- a/src/system/libroot/posix/sys/wait.cpp +++ b/src/system/libroot/posix/sys/wait.cpp @@ -12,6 +12,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/xsi_msg_queue.cpp b/src/system/libroot/posix/sys/xsi_msg_queue.cpp index 6489782a43..910523c0b2 100644 --- a/src/system/libroot/posix/sys/xsi_msg_queue.cpp +++ b/src/system/libroot/posix/sys/xsi_msg_queue.cpp @@ -15,6 +15,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/sys/xsi_sem.cpp b/src/system/libroot/posix/sys/xsi_sem.cpp index 51402a8961..bddeecb762 100644 --- a/src/system/libroot/posix/sys/xsi_sem.cpp +++ b/src/system/libroot/posix/sys/xsi_sem.cpp @@ -15,6 +15,7 @@ #include +#include #include #include #include diff --git a/src/system/libroot/posix/termios.c b/src/system/libroot/posix/termios.c index 0158f86b30..9a6e57bf94 100644 --- a/src/system/libroot/posix/termios.c +++ b/src/system/libroot/posix/termios.c @@ -10,6 +10,8 @@ #include #include +#include + /*! get the attributes of the TTY device at fd */ int @@ -40,7 +42,7 @@ tcsetattr(int fd, int opt, const struct termios *termios) default: // no other valid options - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -74,7 +76,7 @@ tcflow(int fd, int action) break; default: - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -93,7 +95,7 @@ tcflush(int fd, int queueSelector) /*! send zero bits for the specified duration */ int tcsendbreak(int fd, int duration) -{ +{ // Posix spec says this should take ~ 0.25 to 0.5 seconds. // As the interpretation of the duration is undefined, we'll just ignore it return ioctl(fd, TCSBRK, 0); @@ -116,7 +118,7 @@ cfsetispeed(struct termios *termios, speed_t speed) Note that errors from hardware device are detected only until the tcsetattr() function is called */ if (speed > B230400 || (speed & CBAUD) != speed) { - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -138,7 +140,7 @@ cfsetospeed(struct termios *termios, speed_t speed) { /* Check for unaccepted speed values (see above) */ if (speed > B230400 || (speed & CBAUD) != speed) { - errno = EINVAL; + __set_errno(EINVAL); return -1; } diff --git a/src/system/libroot/posix/time/clock_support.cpp b/src/system/libroot/posix/time/clock_support.cpp index f49082655c..6f214f8660 100644 --- a/src/system/libroot/posix/time/clock_support.cpp +++ b/src/system/libroot/posix/time/clock_support.cpp @@ -13,6 +13,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/time/localtime.cpp b/src/system/libroot/posix/time/localtime.cpp index 2486085d0b..6b6c73d11d 100644 --- a/src/system/libroot/posix/time/localtime.cpp +++ b/src/system/libroot/posix/time/localtime.cpp @@ -13,6 +13,7 @@ #include +#include #include "LocaleBackend.h" @@ -58,7 +59,7 @@ extern "C" struct tm* localtime_r(const time_t* inTime, struct tm* tmOut) { if (inTime == NULL) { - errno = EINVAL; + __set_errno(EINVAL); return NULL; } @@ -67,12 +68,12 @@ localtime_r(const time_t* inTime, struct tm* tmOut) status_t status = gLocaleBackend->Localtime(inTime, tmOut); if (status != B_OK) - errno = EOVERFLOW; + __set_errno(EOVERFLOW); return tmOut; } - errno = ENOSYS; + __set_errno(ENOSYS); return NULL; } @@ -90,7 +91,7 @@ extern "C" struct tm* gmtime_r(const time_t* inTime, struct tm* tmOut) { if (inTime == NULL) { - errno = EINVAL; + __set_errno(EINVAL); return NULL; } @@ -99,12 +100,12 @@ gmtime_r(const time_t* inTime, struct tm* tmOut) status_t status = gLocaleBackend->Gmtime(inTime, tmOut); if (status != B_OK) - errno = EOVERFLOW; + __set_errno(EOVERFLOW); return tmOut; } - errno = ENOSYS; + __set_errno(ENOSYS); return NULL; } @@ -113,7 +114,7 @@ extern "C" time_t mktime(struct tm* inTm) { if (inTm == NULL) { - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -123,13 +124,13 @@ mktime(struct tm* inTm) status_t status = gLocaleBackend->Mktime(inTm, timeOut); if (status != B_OK) { - errno = EOVERFLOW; + __set_errno(EOVERFLOW); return -1; } return timeOut; } - errno = ENOSYS; + __set_errno(ENOSYS); return -1; } diff --git a/src/system/libroot/posix/time/nanosleep.c b/src/system/libroot/posix/time/nanosleep.c index eb59b0f29a..faf8fde7c1 100644 --- a/src/system/libroot/posix/time/nanosleep.c +++ b/src/system/libroot/posix/time/nanosleep.c @@ -8,6 +8,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/time/stime.c b/src/system/libroot/posix/time/stime.c index 1948bd17c1..fc8a8e17b4 100644 --- a/src/system/libroot/posix/time/stime.c +++ b/src/system/libroot/posix/time/stime.c @@ -7,6 +7,8 @@ #include #include "syscalls.h" +#include + int stime(const time_t *tp) @@ -14,13 +16,13 @@ stime(const time_t *tp) status_t status; if (tp == NULL) { - errno = EINVAL; + __set_errno(EINVAL); return -1; } status = _kern_set_real_time_clock((bigtime_t)*tp * 1000000); if (status < B_OK) { - errno = status; + __set_errno(status); return -1; } return 0; diff --git a/src/system/libroot/posix/time/strptime.c b/src/system/libroot/posix/time/strptime.c index 02012365da..a5a7904910 100644 --- a/src/system/libroot/posix/time/strptime.c +++ b/src/system/libroot/posix/time/strptime.c @@ -37,6 +37,8 @@ #include #include "timelocal.h" +#include + static char * _strptime(const char *, const char *, struct tm *, int *); #define asizeof(a) (sizeof (a) / sizeof ((a)[0])) @@ -414,13 +416,13 @@ label: time_t t; sverrno = errno; - errno = 0; + __set_errno(0); n = strtol(buf, &cp, 10); if (errno == ERANGE || (long)(t = n) != n) { - errno = sverrno; + __set_errno(sverrno); return 0; } - errno = sverrno; + __set_errno(sverrno); buf = cp; gmtime_r(&t, tm); *GMTp = 1; diff --git a/src/system/libroot/posix/time/timer_support.cpp b/src/system/libroot/posix/time/timer_support.cpp index 1c2f8222d0..74e835837d 100644 --- a/src/system/libroot/posix/time/timer_support.cpp +++ b/src/system/libroot/posix/time/timer_support.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include diff --git a/src/system/libroot/posix/time/wcsftime.c b/src/system/libroot/posix/time/wcsftime.c index 65fa306354..d61c31c396 100644 --- a/src/system/libroot/posix/time/wcsftime.c +++ b/src/system/libroot/posix/time/wcsftime.c @@ -32,6 +32,8 @@ #include #include +#include + /* * Convert date and time to a wide-character string. @@ -82,7 +84,7 @@ wcsftime(wchar_t *wcs, size_t maxsize, const wchar_t *format, */ if (SIZE_MAX / MB_CUR_MAX <= maxsize) { /* maxsize is prepostorously large - avoid int. overflow. */ - errno = EINVAL; + __set_errno(EINVAL); goto error; } if ((dst = malloc(maxsize * MB_CUR_MAX)) == NULL) @@ -104,7 +106,7 @@ error: sverrno = errno; free(sformat); free(dst); - errno = sverrno; + __set_errno(sverrno); return 0; } diff --git a/src/system/libroot/posix/unistd/access.c b/src/system/libroot/posix/unistd/access.c index a9ca6c11d6..dbc14b917c 100644 --- a/src/system/libroot/posix/unistd/access.c +++ b/src/system/libroot/posix/unistd/access.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2002-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/unistd/alarm.c b/src/system/libroot/posix/unistd/alarm.c index e47f6e9261..59ab966658 100644 --- a/src/system/libroot/posix/unistd/alarm.c +++ b/src/system/libroot/posix/unistd/alarm.c @@ -8,6 +8,7 @@ #include #include +#include #include diff --git a/src/system/libroot/posix/unistd/chown.c b/src/system/libroot/posix/unistd/chown.c index 787ea42315..6d389d5e6a 100644 --- a/src/system/libroot/posix/unistd/chown.c +++ b/src/system/libroot/posix/unistd/chown.c @@ -9,6 +9,7 @@ #include +#include #include #include diff --git a/src/system/libroot/posix/unistd/chroot.cpp b/src/system/libroot/posix/unistd/chroot.cpp index f13c6380d9..4e9091dbf2 100644 --- a/src/system/libroot/posix/unistd/chroot.cpp +++ b/src/system/libroot/posix/unistd/chroot.cpp @@ -8,13 +8,15 @@ #include #include +#include + int chroot(const char *path) { status_t error = _kern_change_root(path); if (error != B_OK) { - errno = error; + __set_errno(error); return -1; } diff --git a/src/system/libroot/posix/unistd/close.c b/src/system/libroot/posix/unistd/close.c index c44573deed..44b4138b5b 100644 --- a/src/system/libroot/posix/unistd/close.c +++ b/src/system/libroot/posix/unistd/close.c @@ -11,6 +11,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/unistd/conf.cpp b/src/system/libroot/posix/unistd/conf.cpp index c54ecf1baa..c4a87f2f75 100644 --- a/src/system/libroot/posix/unistd/conf.cpp +++ b/src/system/libroot/posix/unistd/conf.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include @@ -103,7 +104,7 @@ __sysconf(int name) system_info info; err = get_system_info(&info); if (err < B_OK) { - errno = err; + __set_errno(err); return -1; } return info.cpu_count; @@ -115,7 +116,7 @@ __sysconf(int name) int count = 0; err = get_system_info(&info); if (err < B_OK) { - errno = err; + __set_errno(err); return -1; } for (i = 0; i < info.cpu_count; i++) @@ -135,7 +136,7 @@ __sysconf(int name) system_info info; err = get_system_info(&info); if (err < B_OK) { - errno = err; + __set_errno(err); return -1; } return info.max_pages; @@ -145,7 +146,7 @@ __sysconf(int name) system_info info; err = get_system_info(&info); if (err < B_OK) { - errno = err; + __set_errno(err); return -1; } return info.max_pages - info.used_pages; @@ -190,7 +191,7 @@ __sysconf(int name) return 1; } - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -229,7 +230,7 @@ __pathconf_common(struct statvfs *fs, struct stat *st, int ret; ret = fs_stat_dev(fs->f_fsid, &info); if (ret < 0) { - errno = ret; + __set_errno(ret); return -1; } @@ -308,7 +309,7 @@ __pathconf_common(struct statvfs *fs, struct stat *st, return 1; return -1; #endif - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -322,12 +323,12 @@ __pathconf_common(struct statvfs *fs, struct stat *st, case _PC_REC_XFER_ALIGN: case _PC_ALLOC_SIZE_MIN: /* not yet supported */ - errno = EINVAL; + __set_errno(EINVAL); return -1; } - errno = EINVAL; + __set_errno(EINVAL); return -1; } @@ -339,7 +340,7 @@ fpathconf(int fd, int name) struct stat st; int ret; if (fd < 0) { - errno = EBADF; + __set_errno(EBADF); return -1; } ret = fstat(fd, &st); @@ -359,7 +360,7 @@ pathconf(const char *path, int name) struct stat st; int ret; if (path == NULL) { - errno = EFAULT; + __set_errno(EFAULT); return -1; } ret = lstat(path, &st); @@ -379,7 +380,7 @@ confstr(int name, char *buffer, size_t length) char *string = ""; if (!length || !buffer) { - errno = EINVAL; + __set_errno(EINVAL); return 0; } @@ -389,7 +390,7 @@ confstr(int name, char *buffer, size_t length) "/boot/common/bin:/boot/develop/bin"; break; default: - errno = EINVAL; + __set_errno(EINVAL); return 0; } diff --git a/src/system/libroot/posix/unistd/directory.c b/src/system/libroot/posix/unistd/directory.c index 8238514407..57d5e5f7eb 100644 --- a/src/system/libroot/posix/unistd/directory.c +++ b/src/system/libroot/posix/unistd/directory.c @@ -8,18 +8,19 @@ #include #include +#include #include #include -int +int chdir(const char *path) { RETURN_AND_SET_ERRNO(_kern_setcwd(-1, path)); } -int +int fchdir(int fd) { RETURN_AND_SET_ERRNO(_kern_setcwd(fd, NULL)); @@ -35,7 +36,7 @@ getcwd(char *buffer, size_t size) if (buffer == NULL) { buffer = malloc(size = PATH_MAX); if (buffer == NULL) { - errno = B_NO_MEMORY; + __set_errno(B_NO_MEMORY); return NULL; } @@ -47,7 +48,7 @@ getcwd(char *buffer, size_t size) if (allocated) free(buffer); - errno = status; + __set_errno(status); return NULL; } return buffer; diff --git a/src/system/libroot/posix/unistd/dup.c b/src/system/libroot/posix/unistd/dup.c index a585a9ad4d..d5ee4afdb3 100644 --- a/src/system/libroot/posix/unistd/dup.c +++ b/src/system/libroot/posix/unistd/dup.c @@ -7,6 +7,7 @@ #include #include +#include #include #include diff --git a/src/system/libroot/posix/unistd/exec.cpp b/src/system/libroot/posix/unistd/exec.cpp index 78a5d08e79..7c3e5d1ed1 100644 --- a/src/system/libroot/posix/unistd/exec.cpp +++ b/src/system/libroot/posix/unistd/exec.cpp @@ -17,6 +17,8 @@ #include #include +#include + static int count_arguments(va_list list, const char *arg, char ***_env) @@ -59,7 +61,7 @@ do_exec(const char *path, char * const args[], char * const environment[], char **newArgs = NULL; if (path == NULL) { - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } @@ -72,7 +74,7 @@ do_exec(const char *path, char * const args[], char * const environment[], if (argCount == 0) { // we need some more info on what to do... - errno = B_BAD_VALUE; + __set_errno(B_BAD_VALUE); return -1; } @@ -83,7 +85,7 @@ do_exec(const char *path, char * const args[], char * const environment[], strcpy(invoker, "/bin/sh"); status = B_OK; } else { - errno = status; + __set_errno(status); return -1; } } @@ -91,7 +93,7 @@ do_exec(const char *path, char * const args[], char * const environment[], if (invoker[0] != '\0') { status = __parse_invoke_line(invoker, &newArgs, &args, &argCount, path); if (status < B_OK) { - errno = status; + __set_errno(status); return -1; } @@ -104,13 +106,13 @@ do_exec(const char *path, char * const args[], char * const environment[], environment, envCount, &flatArgs, &flatArgsSize); if (status == B_OK) { - errno = _kern_exec(path, flatArgs, flatArgsSize, argCount, envCount, - __gUmask); + __set_errno(_kern_exec(path, flatArgs, flatArgsSize, argCount, envCount, + __gUmask)); // if this call returns, something definitely went wrong free(flatArgs); } else - errno = status; + __set_errno(status); free(newArgs); return -1; @@ -146,7 +148,7 @@ execvp(const char *file, char* const* argv) // get the PATH const char* paths = getenv("PATH"); if (paths == NULL) { - errno = B_ENTRY_NOT_FOUND; + __set_errno(B_ENTRY_NOT_FOUND); return -1; } @@ -185,7 +187,7 @@ execvp(const char *file, char* const* argv) return do_exec(path, argv, environ, true); } - errno = B_ENTRY_NOT_FOUND; + __set_errno(B_ENTRY_NOT_FOUND); return -1; } diff --git a/src/system/libroot/posix/unistd/fork.c b/src/system/libroot/posix/unistd/fork.c index 26565db1bf..a771e9ed2a 100644 --- a/src/system/libroot/posix/unistd/fork.c +++ b/src/system/libroot/posix/unistd/fork.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -138,7 +139,7 @@ fork(void) if (thread < 0) { // something went wrong mutex_unlock(&sForkLock); - errno = thread; + __set_errno(thread); return -1; } diff --git a/src/system/libroot/posix/unistd/getlogin.c b/src/system/libroot/posix/unistd/getlogin.c index c76f5ae0be..61f59a3b3f 100644 --- a/src/system/libroot/posix/unistd/getlogin.c +++ b/src/system/libroot/posix/unistd/getlogin.c @@ -12,6 +12,8 @@ #include #include +#include + char *getlogin() { @@ -19,7 +21,7 @@ char *getlogin() pw = getpwuid(getuid()); if (pw) return pw->pw_name; - errno = ENOMEM; + __set_errno(ENOMEM); return NULL; } diff --git a/src/system/libroot/posix/unistd/hostname.cpp b/src/system/libroot/posix/unistd/hostname.cpp index 35fe1080a5..676f16990e 100644 --- a/src/system/libroot/posix/unistd/hostname.cpp +++ b/src/system/libroot/posix/unistd/hostname.cpp @@ -12,6 +12,8 @@ #include #include +#include + static status_t get_path(char *path, bool create) @@ -34,7 +36,7 @@ sethostname(const char *hostName, size_t nameSize) { char path[B_PATH_NAME_LENGTH]; if (get_path(path, false) != B_OK) { - errno = B_ERROR; + __set_errno(B_ERROR); return -1; } @@ -62,7 +64,7 @@ gethostname(char *hostName, size_t nameSize) char path[B_PATH_NAME_LENGTH]; if (get_path(path, false) != B_OK) { - errno = B_ERROR; + __set_errno(B_ERROR); return -1; } diff --git a/src/system/libroot/posix/unistd/ioctl.c b/src/system/libroot/posix/unistd/ioctl.c index 28bdbb9cfe..a831a2964f 100644 --- a/src/system/libroot/posix/unistd/ioctl.c +++ b/src/system/libroot/posix/unistd/ioctl.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2002-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -9,10 +9,12 @@ #include #include +#include + #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; diff --git a/src/system/libroot/posix/unistd/link.c b/src/system/libroot/posix/unistd/link.c index 0363703a31..491e275c2d 100644 --- a/src/system/libroot/posix/unistd/link.c +++ b/src/system/libroot/posix/unistd/link.c @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -24,7 +25,7 @@ readlinkat(int fd, const char *path, char *buffer, size_t bufferSize) size_t linkLen = bufferSize; status_t status = _kern_read_link(fd, path, buffer, &linkLen); if (status < B_OK) { - errno = status; + __set_errno(status); return -1; } diff --git a/src/system/libroot/posix/unistd/lockf.cpp b/src/system/libroot/posix/unistd/lockf.cpp index cd408bee31..bbbc772b87 100644 --- a/src/system/libroot/posix/unistd/lockf.cpp +++ b/src/system/libroot/posix/unistd/lockf.cpp @@ -7,6 +7,8 @@ #include #include +#include + int lockf(int fileDescriptor, int function, off_t size) @@ -36,10 +38,10 @@ lockf(int fileDescriptor, int function, off_t size) if (fileLock.l_type == F_UNLCK) return 0; - errno = EAGAIN; + __set_errno(EAGAIN); return -1; } else { - errno = EINVAL; + __set_errno(EINVAL); return -1; } diff --git a/src/system/libroot/posix/unistd/lseek.c b/src/system/libroot/posix/unistd/lseek.c index acf14ec27e..ff3ff0f0fe 100644 --- a/src/system/libroot/posix/unistd/lseek.c +++ b/src/system/libroot/posix/unistd/lseek.c @@ -1,4 +1,4 @@ -/* +/* ** Copyright 2001, Manuel J. Petit. All rights reserved. ** Distributed under the terms of the NewOS License. */ @@ -7,6 +7,7 @@ #include +#include #include @@ -15,7 +16,7 @@ lseek(int fd, off_t pos, int whence) { off_t result = _kern_seek(fd, pos, whence); if (result < 0) { - errno = result; + __set_errno(result); return -1; } return result; diff --git a/src/system/libroot/posix/unistd/mknod.c b/src/system/libroot/posix/unistd/mknod.c index b00c6d4ec5..2a28fe22ec 100644 --- a/src/system/libroot/posix/unistd/mknod.c +++ b/src/system/libroot/posix/unistd/mknod.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ @@ -7,11 +7,13 @@ #include #include +#include + int mknod(const char *name, mode_t mode, dev_t dev) { - errno = ENOTSUP; + __set_errno(ENOTSUP); return -1; } @@ -19,7 +21,7 @@ mknod(const char *name, mode_t mode, dev_t dev) int mknodat(int fd, const char *name, mode_t mode, dev_t dev) { - errno = ENOTSUP; + __set_errno(ENOTSUP); return -1; } diff --git a/src/system/libroot/posix/unistd/mount.c b/src/system/libroot/posix/unistd/mount.c index ee22f7f527..25ba9d87b4 100644 --- a/src/system/libroot/posix/unistd/mount.c +++ b/src/system/libroot/posix/unistd/mount.c @@ -1,4 +1,4 @@ -/* +/* ** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. ** Distributed under the terms of the Haiku License. */ @@ -9,21 +9,24 @@ #include #include +#include + + int mount(const char *filesystem, const char *where, const char *device, ulong flags, void *parms, int len); int unmount(const char *path); -int +int mount(const char *filesystem, const char *where, const char *device, ulong flags, void *parms, int len) { - errno = EOPNOTSUPP; + __set_errno(EOPNOTSUPP); return -1; } -int +int unmount(const char *path) { - errno = EOPNOTSUPP; + __set_errno(EOPNOTSUPP); return -1; } diff --git a/src/system/libroot/posix/unistd/pause.c b/src/system/libroot/posix/unistd/pause.c index 8ac7e69a0b..757d184acc 100644 --- a/src/system/libroot/posix/unistd/pause.c +++ b/src/system/libroot/posix/unistd/pause.c @@ -13,6 +13,8 @@ #include #include +#include + int pause(void) @@ -20,7 +22,7 @@ pause(void) sigset_t mask; sigemptyset(&mask); - errno = _kern_sigsuspend(&mask); + __set_errno(_kern_sigsuspend(&mask)); pthread_testcancel(); diff --git a/src/system/libroot/posix/unistd/pipe.c b/src/system/libroot/posix/unistd/pipe.c index 7e665beeea..1c851bf58c 100644 --- a/src/system/libroot/posix/unistd/pipe.c +++ b/src/system/libroot/posix/unistd/pipe.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2008, Ingo Weinhold, ingo_weinhold@gmx.de. All rights reserved. * Distributed under the terms of the MIT License. */ @@ -6,6 +6,7 @@ #include #include +#include #include @@ -14,7 +15,7 @@ pipe(int streams[2]) { status_t error = _kern_create_pipe(streams); if (error != B_OK) { - errno = error; + __set_errno(error); return -1; } diff --git a/src/system/libroot/posix/unistd/process.c b/src/system/libroot/posix/unistd/process.c index 271bd0c669..5714c6ec3b 100644 --- a/src/system/libroot/posix/unistd/process.c +++ b/src/system/libroot/posix/unistd/process.c @@ -11,10 +11,12 @@ #include #include +#include + #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; @@ -23,14 +25,14 @@ extern thread_id __main_thread_id; -pid_t +pid_t getpgrp(void) { return getpgid(__main_thread_id); } -pid_t +pid_t getpid(void) { // this one returns the ID of the main thread @@ -38,7 +40,7 @@ getpid(void) } -pid_t +pid_t getppid(void) { return _kern_process_info(0, PARENT_ID); @@ -64,7 +66,7 @@ getpgid(pid_t process) } -int +int setpgid(pid_t process, pid_t group) { pid_t result = _kern_setpgid(process, group); @@ -85,7 +87,7 @@ setpgrp(void) } -pid_t +pid_t setsid(void) { status_t status = _kern_setsid(); diff --git a/src/system/libroot/posix/unistd/read.c b/src/system/libroot/posix/unistd/read.c index ca43642b35..82ea0e091a 100644 --- a/src/system/libroot/posix/unistd/read.c +++ b/src/system/libroot/posix/unistd/read.c @@ -16,6 +16,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/unistd/sbrk.c b/src/system/libroot/posix/unistd/sbrk.c index 5c57b907b2..42a98380de 100644 --- a/src/system/libroot/posix/unistd/sbrk.c +++ b/src/system/libroot/posix/unistd/sbrk.c @@ -7,6 +7,8 @@ #include #include +#include + /* in hoard wrapper */ extern void *(*sbrk_hook)(long); diff --git a/src/system/libroot/posix/unistd/sync.c b/src/system/libroot/posix/unistd/sync.c index 033622d2db..ed0acbba7d 100644 --- a/src/system/libroot/posix/unistd/sync.c +++ b/src/system/libroot/posix/unistd/sync.c @@ -11,6 +11,7 @@ #include +#include #include @@ -26,7 +27,7 @@ sync(void) { int status = _kern_sync(); if (status < 0) { - errno = status; + __set_errno(status); status = -1; } diff --git a/src/system/libroot/posix/unistd/system.cpp b/src/system/libroot/posix/unistd/system.cpp index 8168a76cdf..a7102ead63 100644 --- a/src/system/libroot/posix/unistd/system.cpp +++ b/src/system/libroot/posix/unistd/system.cpp @@ -11,10 +11,10 @@ #include #include +#include #include - extern "C" int system(const char *command) { diff --git a/src/system/libroot/posix/unistd/truncate.c b/src/system/libroot/posix/unistd/truncate.c index 4cb6e9d9ed..cd5dd152b0 100644 --- a/src/system/libroot/posix/unistd/truncate.c +++ b/src/system/libroot/posix/unistd/truncate.c @@ -11,10 +11,12 @@ #include #include +#include + #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; diff --git a/src/system/libroot/posix/unistd/ttyname.c b/src/system/libroot/posix/unistd/ttyname.c index 9365201147..6a3121fc5f 100644 --- a/src/system/libroot/posix/unistd/ttyname.c +++ b/src/system/libroot/posix/unistd/ttyname.c @@ -1,4 +1,4 @@ -/* +/* * Copyright 2003, Daniel Reinhold, danielre@users.sf.net. All rights reserved. * Copyright 2007, François Revol, mmu_man@users.sf.net. All rights reserved. * Distributed under the terms of the MIT License. @@ -15,6 +15,9 @@ #include #include +#include + + /** * give the name of a tty fd. threadsafe. * @param fd the tty to get the name from. @@ -53,7 +56,7 @@ ttyname(int fd) int err = ttyname_r(fd, pathname, sizeof(pathname)); if (err != 0) { - errno = err; + __set_errno(err); return NULL; } return pathname; diff --git a/src/system/libroot/posix/unistd/ualarm.c b/src/system/libroot/posix/unistd/ualarm.c index 927827ac6b..36acd6e467 100644 --- a/src/system/libroot/posix/unistd/ualarm.c +++ b/src/system/libroot/posix/unistd/ualarm.c @@ -8,6 +8,7 @@ #include #include +#include #include diff --git a/src/system/libroot/posix/unistd/usergroup.cpp b/src/system/libroot/posix/unistd/usergroup.cpp index b9fa1b0d14..97f31cff12 100644 --- a/src/system/libroot/posix/unistd/usergroup.cpp +++ b/src/system/libroot/posix/unistd/usergroup.cpp @@ -17,13 +17,15 @@ #include #include +#include + template static inline T set_errno_if_necessary(const T& result) { if (result < 0) { - errno = result; + __set_errno(result); return -1; } @@ -55,7 +57,7 @@ getgid(void) } -uid_t +uid_t getuid(void) { return _kern_getuid(false); diff --git a/src/system/libroot/posix/unistd/usleep.c b/src/system/libroot/posix/unistd/usleep.c index d8ca9f0785..8e52f68890 100644 --- a/src/system/libroot/posix/unistd/usleep.c +++ b/src/system/libroot/posix/unistd/usleep.c @@ -1,4 +1,4 @@ -/* +/* ** Copyright 2001, Manuel J. Petit. All rights reserved. ** Distributed under the terms of the NewOS License. */ @@ -7,13 +7,16 @@ #include #include +#include + + int usleep(unsigned useconds) { int err; err = snooze_until(system_time() + (bigtime_t)(useconds), B_SYSTEM_TIMEBASE); if (err < 0) { - errno = err; + __set_errno(err); return -1; } return 0; diff --git a/src/system/libroot/posix/unistd/write.c b/src/system/libroot/posix/unistd/write.c index 27febf3f51..5776ea861a 100644 --- a/src/system/libroot/posix/unistd/write.c +++ b/src/system/libroot/posix/unistd/write.c @@ -14,6 +14,7 @@ #include +#include #include diff --git a/src/system/libroot/posix/user_group_common.cpp b/src/system/libroot/posix/user_group_common.cpp index 4de8deafc8..6249d3b900 100644 --- a/src/system/libroot/posix/user_group_common.cpp +++ b/src/system/libroot/posix/user_group_common.cpp @@ -15,6 +15,7 @@ #include +#include #include #include #include diff --git a/src/system/libroot/posix/utime.c b/src/system/libroot/posix/utime.c index 5223b4b7f1..5fa8d26402 100644 --- a/src/system/libroot/posix/utime.c +++ b/src/system/libroot/posix/utime.c @@ -11,12 +11,13 @@ #include +#include #include #define RETURN_AND_SET_ERRNO(err) \ if (err < 0) { \ - errno = err; \ + __set_errno(err); \ return -1; \ } \ return err; diff --git a/src/system/libroot/posix/wchar/mbrtowc.cpp b/src/system/libroot/posix/wchar/mbrtowc.cpp index edd26a5c42..fc8db68ea5 100644 --- a/src/system/libroot/posix/wchar/mbrtowc.cpp +++ b/src/system/libroot/posix/wchar/mbrtowc.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "LocaleBackend.h" @@ -42,7 +43,7 @@ __mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps) if (*s < 0) { // char is non-ASCII - errno = EILSEQ; + __set_errno(EILSEQ); return (size_t)-1; } @@ -60,12 +61,12 @@ __mbrtowc(wchar_t* pwc, const char* s, size_t n, mbstate_t* ps) return (size_t)-2; if (status == B_BAD_DATA) { - errno = EILSEQ; + __set_errno(EILSEQ); return (size_t)-1; } if (status != B_OK) { - errno = EINVAL; + __set_errno(EINVAL); return (size_t)-1; } diff --git a/src/system/libroot/posix/wchar/mbtowc.c b/src/system/libroot/posix/wchar/mbtowc.c index e7f411f689..5d477798b0 100644 --- a/src/system/libroot/posix/wchar/mbtowc.c +++ b/src/system/libroot/posix/wchar/mbtowc.c @@ -5,6 +5,7 @@ #include +#include #include @@ -15,7 +16,7 @@ __mbtowc(wchar_t* pwc, const char* s, size_t n) int result = mbrtowc(pwc, s, n, &internalMbState); if (result == -2) { - errno = EILSEQ; + __set_errno(EILSEQ); result = -1; } diff --git a/src/system/libroot/posix/wchar/wcrtomb.cpp b/src/system/libroot/posix/wchar/wcrtomb.cpp index 3ef65e7f2b..05311af3ba 100644 --- a/src/system/libroot/posix/wchar/wcrtomb.cpp +++ b/src/system/libroot/posix/wchar/wcrtomb.cpp @@ -7,6 +7,7 @@ #include #include +#include #include "LocaleBackend.h" @@ -36,7 +37,7 @@ __wcrtomb(char* s, wchar_t wc, mbstate_t* ps) if (wc > 127) { // char is non-ASCII - errno = EILSEQ; + __set_errno(EILSEQ); return (size_t)-1; } @@ -50,12 +51,14 @@ __wcrtomb(char* s, wchar_t wc, mbstate_t* ps) if (status == B_BAD_INDEX) return (size_t)-2; + if (status == B_BAD_DATA) { - errno = EILSEQ; + __set_errno(EILSEQ); return (size_t)-1; } + if (status != B_OK) { - errno = EINVAL; + __set_errno(EINVAL); return (size_t)-1; }