os_test.c revision 9bea4c13fca0e3bb4b719dcb3ed63d47d479294e
1 2#include <stdio.h> 3#include <stdlib.h> 4#include <string.h> 5 6// This program determines which OS that this Valgrind installation 7// supports, which depends on what was chosen at configure-time. 8// 9// We return: 10// - 0 if the machine matches the asked-for OS 11// - 1 if it doesn't match but does match the name of another OS 12// - 2 if it doesn't match the name of any OS 13// - 3 if there was a usage error (it also prints an error message) 14 15// Nb: When updating this file for a new OS, add the name to 16// 'all_OSes' as well as adding go(). 17 18#define False 0 19#define True 1 20typedef int Bool; 21 22char* all_OSes[] = { 23 "linux", 24 "aix5", 25 "darwin", 26 NULL 27}; 28 29static Bool go(char* OS) 30{ 31#if defined(VGO_linux) 32 if ( 0 == strcmp( OS, "linux" ) ) return True; 33 34#elif defined(VGO_aix5) 35 if ( 0 == strcmp( OS, "aix5" ) ) return True; 36 37#elif defined(VGO_darwin) 38 if ( 0 == strcmp( OS, "darwin" ) ) return True; 39 40#else 41# error Unknown OS 42#endif // VGO_* 43 44 return False; 45} 46 47//--------------------------------------------------------------------------- 48// main 49//--------------------------------------------------------------------------- 50int main(int argc, char **argv) 51{ 52 int i; 53 if ( argc != 2 ) { 54 fprintf( stderr, "usage: os_test <OS-type>\n" ); 55 exit(3); // Usage error. 56 } 57 if (go( argv[1] )) { 58 return 0; // Matched. 59 } 60 for (i = 0; NULL != all_OSes[i]; i++) { 61 if ( 0 == strcmp( argv[1], all_OSes[i] ) ) 62 return 1; // Didn't match, but named another OS. 63 } 64 return 2; // Didn't match any OSes. 65} 66 67