Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if errno_t is defined?

Tags:

c++

typedef

errno

I'm compiling code using gcc that comes from Visual C++ 2008. The code is using errno_t, but in some versions of gcc headers including <errno.h> doesn't define the type. How do I detect if the type is defined? Is there a define that signals that the type was defined? In the case it isn't defined I'd like to provide the typedef to let the code compile correctly on all platforms.

like image 919
vividos Avatar asked Sep 23 '09 08:09

vividos


2 Answers

Microsoft's errno_t is redundant. errno is defined by the ISO C standard to be a modifiable lvalue of type int. If your code needs to store errno values, then you should put them into an int.

Do a global search and replace s/errno_t/int/ and you're done.

Edit: Also, you shouldn't be providing a typedef int errno_t in your code, because all names that end with _t are reserved.

like image 149
alex tingle Avatar answered Oct 14 '22 08:10

alex tingle


You can't check for a typedef the way you can for a macro, so this is a bit on the tricky side. If you're using autoconf, this patch shows the minimum changes that you need to have autoconf check for the presence of errno_t and define it if it's missing (the typedef would be placed in a file that includes your generated config.h and is included by all files that need errno_t). If you're not using autoconf you need to come up with some way to do the same thing within your build system, or a very clever set of tests against compiler version macros.

like image 38
hobbs Avatar answered Oct 14 '22 10:10

hobbs