jaydio icon indicating copy to clipboard operation
jaydio copied to clipboard

get C macro values from the compiler

Open guoci opened this issue 3 years ago • 4 comments

macro values may vary across OSes

guoci avatar Feb 19 '22 19:02 guoci

Hey, thanks for the PR! Could you provide some comments on which OSes deviate from the constants here? Originally this project is targeted primarily at Linux and I'm not aware of which other OSes support O_DIRECT; e.g. I don't see it in BSD.

Also, I'm not too fond of the idea of spinning up another process in a statically-scoped context, but it's been a while since I've used Java so maybe this sort of thing is standard practice? Either way I'd prefer a different approach that doesn't require spawning other processes, and that has the current constants available as a fallback in case something goes wrong.

smacke avatar Mar 27 '22 23:03 smacke

My comment was not clear, I meant across Linux distros. The hardcoded macro value in Jaydio was triggering a bug. In that particular distro, it was for O_DIRECTORY instead of O_DIRECT. I do not know of any way to obtain the values without gcc. We could try to scan the system C headers with Java code, but that can get complicated, a macro symbol can be defined as another macro symbol, which must be resolved to get the value.

guoci avatar Mar 28 '22 17:03 guoci

Thanks for the extra context! Which distro had different constants from the hardcoded ones?

smacke avatar Mar 28 '22 18:03 smacke

It's Ubuntu 20.04.4 LTS (GNU/Linux 5.11.0-1028-aws aarch64). The CPU is Arm-based AWS Graviton2.

fcyu avatar Mar 30 '22 22:03 fcyu