[RFC] bb-wide errno optimization
Rich Felker
dalias at aerifal.cx
Sun Jul 16 05:57:43 UTC 2006
while reading ash.c i noticed an interesting hack to save some space:
----------------------------------------------------------------------
#ifdef __GLIBC__
/* glibc sucks */
static int *dash_errno;
#undef errno
#define errno (*dash_errno)
#endif
...
ash_main(...)
{
...
#ifdef __GLIBC__
dash_errno = __errno_location();
#endif
----------------------------------------------------------------------
while this looks ugly and nonportable i think it's possible to do a
portable version of this that would work with any libc and prevent the
overhead of accessing errno through a function call or tls variable.
(admittedly the latter is not as expensive but not free either). the
idea is something like:
----------------------------------------------------------------------
/* in libbb.h */
#ifndef IN_BB_MAIN
extern int *bb_errno;
#undef errno
#define errno (*bb_errno)
#endif
/* in main() */
bb_errno = &errno;
----------------------------------------------------------------------
comments?
rich
More information about the busybox
mailing list