1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sal.hxx" 26 27 //######################################## 28 // includes 29 30 #ifdef WNT // Windows 31 #define UNICODE 32 #define _UNICODE 33 #define WIN32_LEAN_AND_MEAN 34 #include <tchar.h> 35 #else 36 #include <unistd.h> 37 #endif 38 39 #include <stdio.h> 40 #include <stdlib.h> 41 #include <iostream> 42 #include <fstream> 43 44 #include <rtl/ustring.hxx> 45 46 //######################################## 47 // defines 48 49 #ifdef WNT 50 # define SLEEP(t) (Sleep((t)*1000)) 51 #else 52 # define SLEEP(t) (sleep((t))) 53 #endif 54 55 //######################################## 56 void wait_for_seconds(char* time) 57 { 58 SLEEP(atoi(time)); 59 } 60 61 //######################################## 62 63 #ifdef WNT 64 //######################################## 65 void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size) 66 { 67 LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW); 68 WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL); 69 } 70 //######################################## 71 void dump_env(char* file_path) 72 { 73 LPTSTR env = reinterpret_cast<LPTSTR>( 74 GetEnvironmentStrings()); 75 LPTSTR p = env; 76 77 std::ofstream file(file_path); 78 79 char buffer[32767]; 80 while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p))) 81 { 82 w_to_a(p, buffer, sizeof(buffer)); 83 file << buffer << std::endl; 84 p += l + 1; 85 } 86 FreeEnvironmentStrings(env); 87 } 88 #else 89 extern char** environ; 90 91 void dump_env(char* file_path) 92 { 93 std::ofstream file(file_path); 94 for (int i = 0; NULL != environ[i]; i++) 95 file << environ[i] << std::endl; 96 } 97 #endif 98 99 //######################################## 100 int main(int argc, char* argv[]) 101 { 102 rtl::OUString s; 103 104 //t_print("Parameter: "); 105 printf("child process Parameter: "); 106 for (int i = 1; i < argc; i++) 107 printf("%s ", argv[i]); 108 printf("\n"); 109 110 if (argc > 2) 111 { 112 if (0 == strcmp("-join", argv[1])) 113 { 114 wait_for_seconds(argv[2]); 115 } 116 else if (0 == strcmp("-env", argv[1])) 117 { 118 dump_env(argv[2]); 119 } 120 } 121 122 return (0); 123 } 124 125