/* save_arguments - Save argc and argv as passed into the program for the file * we output. * If either the LLVMPROF_OUTPUT environment variable or the -llvmprof-output * command line argument are set then change OutputFilename to the provided * value. The command line argument value overrides the environment variable. */ int save_arguments(int argc, const char **argv) { unsigned Length, i; if (!SavedEnvVar && !SavedArgs) check_environment_variable(); if (SavedArgs || !argv) return argc; /* This can be called multiple times */ /* Check to see if there are any arguments passed into the program for the * profiler. If there are, strip them off and remember their settings. */ while (argc > 1 && !strncmp(argv[1], "-llvmprof-", 10)) { /* Ok, we have an llvmprof argument. Remove it from the arg list and decide * what to do with it. */ const char *Arg = argv[1]; memmove((char**)&argv[1], &argv[2], (argc-1)*sizeof(char*)); --argc; if (!strcmp(Arg, "-llvmprof-output")) { if (argc == 1) puts("-llvmprof-output requires a filename argument!"); else { OutputFilename = strdup(argv[1]); if (SavedEnvVar) { free((void *)SavedEnvVar); SavedEnvVar = 0; } memmove((char**)&argv[1], &argv[2], (argc-1)*sizeof(char*)); --argc; } } else { printf("Unknown option to the profiler runtime: '%s' - ignored.\n", Arg); } } for (Length = 0, i = 0; i != (unsigned)argc; ++i) Length += strlen(argv[i])+1; /* Defensively check for a zero length, even though this is unlikely * to happen in practice. This avoids calling malloc() below with a * size of 0. */ if (Length == 0) { SavedArgs = 0; SavedArgsLength = 0; return argc; } SavedArgs = (char*)malloc(Length); for (Length = 0, i = 0; i != (unsigned)argc; ++i) { unsigned Len = strlen(argv[i]); memcpy(SavedArgs+Length, argv[i], Len); Length += Len; SavedArgs[Length++] = ' '; } SavedArgsLength = Length; return argc; }
int main(int argc, char ** argv) { int some_test_failed; argc = argc; argv = argv; /* turn off warnings */ some_test_failed = 0; if (check_environment_variable("V1", '1')) some_test_failed = 1; if (check_environment_variable("V2", '2')) some_test_failed = 1; if (check_environment_variable("V3", '3')) some_test_failed = 1; if (check_environment_variable("V4", '4')) some_test_failed = 1; if (check_environment_variable("V5", '5')) some_test_failed = 1; if (check_environment_variable("V6", '6')) some_test_failed = 1; if (check_environment_variable("V7", '7')) some_test_failed = 1; if (check_environment_variable("V8", '8')) some_test_failed = 1; if (check_environment_variable("V9", '9')) some_test_failed = 1; if (check_environment_variable("V10", 'A')) some_test_failed = 1; if (check_environment_variable("V11", 'B')) some_test_failed = 1; if (some_test_failed) { printf("FAILURE\n"); } else { printf("SUCCESS\n"); } return some_test_failed; }