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