1 // Copyright 2018 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifdef UNSAFE_BUFFERS_BUILD 6 // TODO(crbug.com/40284755): Remove this and spanify to fix the errors. 7 #pragma allow_unsafe_buffers 8 #endif 9 10 #include <stdio.h> 11 #include <stdlib.h> 12 #include <string.h> 13 14 // Simple testing command, used to exercise child process launcher calls. 15 // 16 // Usage: 17 // echo_test_helper [-x exit_code] arg0 arg1 arg2... 18 // Prints arg0..n to stdout with space delimiters between args, 19 // returning "exit_code" if -x is specified. 20 // 21 // echo_test_helper -e env_var 22 // Prints the environmental variable |env_var| to stdout. main(int argc,char ** argv)23int main(int argc, char** argv) { 24 if (strcmp(argv[1], "-e") == 0) { 25 if (argc != 3) { 26 return 1; 27 } 28 29 const char* env = getenv(argv[2]); 30 if (env != NULL) { 31 printf("%s", env); 32 } 33 } else { 34 int return_code = 0; 35 int start_idx = 1; 36 37 if (strcmp(argv[1], "-x") == 0) { 38 return_code = atoi(argv[2]); 39 start_idx = 3; 40 } 41 42 for (int i = start_idx; i < argc; ++i) { 43 printf((i < argc - 1 ? "%s " : "%s"), argv[i]); 44 } 45 46 return return_code; 47 } 48 } 49