njn | 61485ab | 2009-03-04 04:15:16 +0000 | [diff] [blame^] | 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 |
| 20 | typedef int Bool; |
| 21 | |
| 22 | char* all_OSes[] = { |
| 23 | "linux", |
| 24 | "aix5", |
| 25 | NULL |
| 26 | }; |
| 27 | |
| 28 | static Bool go(char* OS) |
| 29 | { |
| 30 | #if defined(VGO_linux) |
| 31 | if ( 0 == strcmp( OS, "linux" ) ) return True; |
| 32 | |
| 33 | #elif defined(VGO_aix5) |
| 34 | if ( 0 == strcmp( OS, "aix5" ) ) return True; |
| 35 | |
| 36 | #else |
| 37 | # error Unknown OS |
| 38 | #endif // VGO_* |
| 39 | |
| 40 | return False; |
| 41 | } |
| 42 | |
| 43 | //--------------------------------------------------------------------------- |
| 44 | // main |
| 45 | //--------------------------------------------------------------------------- |
| 46 | int main(int argc, char **argv) |
| 47 | { |
| 48 | int i; |
| 49 | if ( argc != 2 ) { |
| 50 | fprintf( stderr, "usage: os_test <OS-type>\n" ); |
| 51 | exit(3); // Usage error. |
| 52 | } |
| 53 | if (go( argv[1] )) { |
| 54 | return 0; // Matched. |
| 55 | } |
| 56 | for (i = 0; NULL != all_OSes[i]; i++) { |
| 57 | if ( 0 == strcmp( argv[1], all_OSes[i] ) ) |
| 58 | return 1; // Didn't match, but named another OS. |
| 59 | } |
| 60 | return 2; // Didn't match any OSes. |
| 61 | } |
| 62 | |