Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TEMP_FAILURE_RETRY and __USE_GNU

Tags:

c

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?

like image 247
SlappyTheFish Avatar asked Nov 28 '11 21:11

SlappyTheFish


2 Answers

__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.

like image 191
Macmade Avatar answered Oct 17 '22 15:10

Macmade


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.

like image 35
kralyk Avatar answered Oct 17 '22 15:10

kralyk