Is there a way to conditionally compile based on the existence of a constant?

Viewed 154

The libc library defines a number of constants that can be passed as flags to open() such as O_APPEND, O_CREAT, etc. Some of these flags are only defined for certain OS targets. It'd be nice if there was a way to freely use O_WHATEVER in my code without worrying about whether it was actually defined in libc:

#[cfg(???)]
const O_WHATEVER = libc::O_WHATEVER;
#[cfg(not(???))]
const O_WHATEVER = 0;

It'd be nice if the ??? in my example above was some kind of is_defined(libc::O_WHATEVER). Otherwise, I'd need to figure out all of the OS combinations in which O_WHATEVER is defined in libc and that'd be a real pain.

1 Answers
Related