Re: git: d58339f39874 - main - tzcode: Drop libc namespace
- In reply to: Konstantin Belousov : "Re: git: d58339f39874 - main - tzcode: Drop libc namespace"
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 29 Sep 2025 05:19:28 UTC
Konstantin Belousov <kostikbel@gmail.com> writes:
> Dag-Erling Smørgrav <des@FreeBSD.org> writes:
> > If we really want to do what you suggest, there are better
> > ways (like what macOS does).
> I have no idea about MacOS/what is used by Mach-O. Can you provide some
> hints or links, please?
They use macros in the header that contains the prototype to rename
functions when there are multiple variants. In our case it would look
like this:
(in sys/sys/cdefs.h)
#ifdef __LIBC
#define __LIBC_SYM(sym) __asm("_" #sym)
#else
#define __LIBC_SYM(sym)
#endif __LIBC
(in include/fcntl.h)
int open(const char *, int, ...) __LIBC_SYM(open);
(in lib/lib{c,sys,thr}/Makefile)
CFLAGS+=-D__LIBC
This allows code in libc to use open() instead of _open() and not have
to worry about needing to include "namespace.h" and "un-namespace.h" in
the right places. It also means simply adding __LIBC to any prototype
(and a __weak_reference in the correct place) automatically protects
every call to that function in lib{c,sys,thr} without having to chase
them all down.
DES
--
Dag-Erling Smørgrav - des@FreeBSD.org