Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
|
Mark Seaborn
2012/03/13 01:05:20
I think this file belongs in a directory with "tes
halyavin
2012/03/13 12:48:27
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <cstdio> | |
| 6 #include <cstring> | |
| 7 | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/process_util.h" | |
| 10 | |
| 11 const char kArgs[] = "--args"; | |
| 12 const char kEvalCommand[] = "--eval-command"; | |
| 13 const char kNaClIrt[] = "nacl-irt "; | |
| 14 | |
| 15 int main(int argc, char** argv) { | |
| 16 if (argc < 3) { | |
| 17 // Too few arguments. | |
| 18 return 1; | |
|
Mark Seaborn
2012/03/13 01:05:20
Having different numbers for each failure is weird
halyavin
2012/03/13 12:48:27
Done.
| |
| 19 } | |
| 20 if (strcmp(argv[1], kEvalCommand) != 0) { | |
| 21 // First argument should be --eval-command. | |
| 22 return 2; | |
| 23 } | |
| 24 if (strlen(argv[2]) < strlen(kNaClIrt)) { | |
| 25 // Second argument should start with nacl-irt. | |
| 26 return 3; | |
| 27 } | |
| 28 if (strncmp(argv[2], kNaClIrt, strlen(kNaClIrt)) != 0) { | |
| 29 // Second argument should start with nacl-irt. | |
| 30 return 4; | |
| 31 } | |
| 32 char* irtFileName = &argv[2][strlen(kNaClIrt)]; | |
|
brettw
2012/03/13 05:57:49
style: irt_file_name (no caps in var names)
halyavin
2012/03/13 12:48:27
Done.
| |
| 33 FILE* irtFile = fopen(irtFileName, "r"); | |
|
brettw
2012/03/13 05:57:49
Ditto
halyavin
2012/03/13 12:48:27
Done.
| |
| 34 if (irtFile == NULL) { | |
| 35 // nacl-irt parameter must be a file name. | |
| 36 return 5; | |
| 37 } | |
| 38 fclose(irtFile); | |
| 39 int i = 3; | |
| 40 // Skip additional --eval-command parameters. | |
| 41 while (i < argc) { | |
| 42 if (strcmp(argv[i], kArgs) == 0) { | |
| 43 i++; | |
| 44 break; | |
| 45 } | |
| 46 if (strcmp(argv[i], kEvalCommand) == 0) { | |
| 47 i += 2; | |
| 48 if (i > argc) { | |
| 49 // Command line ends with --eval-command switch without value. | |
| 50 return 6; | |
| 51 } | |
| 52 } | |
| 53 // Unknown argument | |
| 54 return 7; | |
| 55 } | |
| 56 if (i >= argc) { | |
| 57 // --args not found. | |
| 58 return 8; | |
| 59 } | |
| 60 | |
| 61 CommandLine::StringVector arguments; | |
| 62 for (; i < argc; i++) { | |
| 63 arguments.push_back( | |
| 64 CommandLine::StringType(argv[i], argv[i] + strlen(argv[i]))); | |
| 65 } | |
| 66 CommandLine cmd_line(arguments); | |
| 67 if (!base::LaunchProcess(cmd_line, base::LaunchOptions(), NULL)) { | |
| 68 // process is not launched successfully | |
| 69 return 9; | |
| 70 } | |
| 71 return 0; | |
| 72 } | |
| OLD | NEW |