• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Chromium Authors. All rights reserved.
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 <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 
9 // Simple testing command, used to exercise child process launcher calls.
10 //
11 // Usage:
12 //        echo_test_helper [-x exit_code] arg0 arg1 arg2...
13 //        Prints arg0..n to stdout with space delimiters between args,
14 //        returning "exit_code" if -x is specified.
15 //
16 //        echo_test_helper -e env_var
17 //        Prints the environmental variable |env_var| to stdout.
main(int argc,char ** argv)18 int main(int argc, char** argv) {
19   if (strcmp(argv[1], "-e") == 0) {
20     if (argc != 3) {
21       return 1;
22     }
23 
24     const char* env = getenv(argv[2]);
25     if (env != NULL) {
26       printf("%s", env);
27     }
28   } else {
29     int return_code = 0;
30     int start_idx = 1;
31 
32     if (strcmp(argv[1], "-x") == 0) {
33       return_code = atoi(argv[2]);
34       start_idx = 3;
35     }
36 
37     for (int i = start_idx; i < argc; ++i) {
38       printf((i < argc - 1 ? "%s " : "%s"), argv[i]);
39     }
40 
41     return return_code;
42   }
43 }
44