libroot_build: Rework errno assignment.

With the old code, if the currentErrno hadn't changed, but was in
fact re-assigned more recently than the local errno was, then we
would wind up incorrectly return the local value instead of the
system value. This was the cause of the build mimeset not working
properly when run in recursive mode on Haiku.

So, instead, create a wrapper struct to make assignment of the
local errno always pass through to the system one, so they never
get out of sync in the first place.
This commit is contained in:
Augustin Cavalier
2026-04-09 14:09:52 -04:00
parent 95c8251d75
commit 744616c074
2 changed files with 56 additions and 31 deletions
+27 -6
View File
@@ -494,23 +494,44 @@
#define ENOEXEC HAIKU_ENOEXEC
#define EPIPE HAIKU_EPIPE
#define ENOATTR HAIKU_ENOATTR
#undef errno
#define errno (*_haiku_build_errno())
#elif defined(HAIKU_HOST_PLATFORM_HAIKU)
# include <../os/support/Errors.h>
# include_next <Errors.h>
#endif // ! BUILDING_HAIKU_ERROR_MAPPER
#ifdef __cplusplus
extern "C" {
#endif
extern int *_haiku_build_errno();
extern const int _haiku_build_errno();
extern void _haiku_build_set_errno(int error);
extern int _haiku_to_host_error(int error);
#ifdef __cplusplus
}
} // extern "C"
struct BuildErrnoWrapper {
int operator=(int value)
{
_haiku_build_set_errno(value);
return value;
}
operator int()
{
return _haiku_build_errno();
}
};
#endif
/* build-specific code */
#ifndef BUILDING_HAIKU_ERROR_MAPPER
#undef errno
#ifndef __cplusplus
#define errno (_haiku_build_errno())
#else
extern BuildErrnoWrapper build_errno;
#define errno build_errno
#endif
#endif // ! BUILDING_HAIKU_ERROR_MAPPER
#endif /* _BUILD_ERRORS_H */