scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 62f15e1be888bbe090e85f507162bea06bdb0642
parent 139c892411c2301d962cc592cbf86e45f8cbd8ec
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue,  7 Feb 2023 09:08:04 +0100

ar: Try to use unlink() instead of remove()

It was known that ar was calling remove() that is not
signal safe from a signal handler. The reason was
that ar is designed as portable code and it cannot
call the signal safe unlink() function. This commit
uses the preprocessor to detect some common macros
defined by UNIX compilers to redirect remove()
to unlink() in that case.

Diffstat:
Msrc/cmd/ar.c | 14++++++++++++++
1 file changed, 14 insertions(+), 0 deletions(-)

diff --git a/src/cmd/ar.c b/src/cmd/ar.c @@ -37,6 +37,18 @@ struct member { long long date; }; +/* + * Best effort to try avoid calling remove from a signal + * handler is to detect that we are in an UNIX + * system and redirect with the preprocessor remove + * to unlink that is defined as signal safe. + */ +#if defined(__unix) || defined(__unix__) +#include <unistd.h> +#undef remove +#define remove unlink +#endif + static void cleanup(void) { @@ -48,6 +60,8 @@ cleanup(void) } } +#undef remove + static char * errstr(void) {