I'm on Ubuntu 10.04 using GCC and I want to use the macro TEMP_FAILURE_RETRY as described here:
http://www.gnu.org/s/hello/manual/libc/Interrupted-Primitives.html
However, when I compile I got the following error:
undefined reference to `TEMP_FAILURE_RETRY'
I looked in unistd.h where the macro is defined and it is preceded by:
#ifdef __USE_GNU
How do I get my code to compile and use this macro? Can I simply wrap it using the same #ifdef __USE_GNU in my code?
__USE_GNU
is an internal macro, so you shouldn't define it yourself.
But you may define _GNU_SOURCE
, either in your code, or when compiling (using the -D
option).
I think defining this one will help to make TEMP_FAILURE_RETRY
available.
Using _GNU_SOURCE
may have implications for portability of the code, it brings in a lot of other stuff besides TEMP_FAILURE_RETRY
. If you only need the functionality of TEMP_FAILURE_RETRY
, you may as well define similar macro yourself, here's a standard C version that doesn't use any GNU extensions:
#define CALL_RETRY(retvar, expression) do { \
retvar = (expression); \
} while (retvar == -1 && errno == EINTR);
where in retvar
you pass the name of a variable where you want the return value stored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With