blob: d13bd6043bae8be26555be55ec85ea5a400e0e1b [file] [log] [blame]
njn61485ab2009-03-04 04:15:16 +00001
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",
njnf76d27a2009-05-28 01:53:07 +000024 "darwin",
njn61485ab2009-03-04 04:15:16 +000025 NULL
26};
27
28static Bool go(char* OS)
29{
30#if defined(VGO_linux)
31 if ( 0 == strcmp( OS, "linux" ) ) return True;
32
njnf76d27a2009-05-28 01:53:07 +000033#elif defined(VGO_darwin)
34 if ( 0 == strcmp( OS, "darwin" ) ) return True;
njn61485ab2009-03-04 04:15:16 +000035
36#else
37# error Unknown OS
38#endif // VGO_*
39
40 return False;
41}
42
43//---------------------------------------------------------------------------
44// main
45//---------------------------------------------------------------------------
46int 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