I have some tools I'm working on in portable C that works in Windows Visual Studio 2008 and gcc in Ubuntu Linux based on #ifdef _WIN32 but adding support for Solaris seems to be trickier, especially if I want to support cc as well as gcc.
For one example I have some code which sprintfs into an allocated memory buffer which uses vasprintf on Linux/gcc and _vscprintf/vsprintf on Windows/MSVC. Neither are available on Solaris where I could use vsnprintf but I have no idea what to add to my #ifdefs or whether I should move to something else.
Hopefully I don't have to move to configure with cygwin, mingw.
The autoconf(1) manual has a section on portable C programming.
The only real way to do a test like this is to use something like gnu's autoconf + configure (or just plain configure). You can then test to see if vsprintf exists, failing that test for vasprintf, failing that test for vsnprintf, etc.. You can then get configure to define HAS_VSPRINTF and the like to use in your code, and write a wrapper function around the correct function.
This would be the most portable way to test,and the most portable way to then code up a solution, though perhaps also the most cumbersome - it'd definitely be what I'd do for production code though.
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