Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #if ( defined WNT ) // Windows
21 : # define UNICODE
22 : # define _UNICODE
23 : # define WIN32_LEAN_AND_MEAN
24 : # include <windows.h>
25 : # include <tchar.h>
26 : #else
27 : # include <unistd.h>
28 : #endif
29 :
30 : #include <stdio.h>
31 : #include <stdlib.h>
32 : #include <iostream>
33 : #include <fstream>
34 : #include <string.h>
35 :
36 : #include <rtl/ustring.hxx>
37 :
38 : #ifdef UNX
39 : #if defined( MACOSX )
40 : # include <crt_externs.h>
41 : # define environ (*_NSGetEnviron())
42 : # else
43 : extern char** environ;
44 : # endif
45 : #endif
46 :
47 : #ifdef WNT
48 : # define SLEEP(t) (Sleep((t)*1000))
49 : #else
50 : # define SLEEP(t) (sleep((t)))
51 : #endif
52 :
53 0 : void wait_for_seconds(char* time)
54 : {
55 0 : SLEEP(atoi(time));
56 0 : }
57 :
58 : #ifdef WNT
59 :
60 : void w_to_a(LPCTSTR _strW, LPSTR strA, DWORD size)
61 : {
62 : LPCWSTR strW = reinterpret_cast<LPCWSTR>(_strW);
63 : WideCharToMultiByte(CP_ACP, 0, strW, -1, strA, size, NULL, NULL);
64 : }
65 :
66 : void dump_env(char* file_path)
67 : {
68 : LPTSTR env = reinterpret_cast<LPTSTR>(
69 : GetEnvironmentStrings());
70 : LPTSTR p = env;
71 :
72 : std::ofstream file(file_path);
73 :
74 : char buffer[32767];
75 : while (size_t l = _tcslen(reinterpret_cast<wchar_t*>(p)))
76 : {
77 : w_to_a(p, buffer, sizeof(buffer));
78 : file << buffer << '\0';
79 : p += l + 1;
80 : }
81 : FreeEnvironmentStrings(env);
82 : }
83 : #else
84 4 : void dump_env(char* file_path)
85 : {
86 4 : std::ofstream file(file_path);
87 3238 : for (int i = 0; NULL != environ[i]; ++i)
88 3238 : file << environ[i] << '\0';
89 4 : }
90 : #endif
91 :
92 4 : int main(int argc, char* argv[])
93 : {
94 4 : if (argc > 2)
95 : {
96 4 : if (0 == strcmp("-join", argv[1]))
97 0 : wait_for_seconds(argv[2]);
98 4 : else if (0 == strcmp("-env", argv[1]))
99 4 : dump_env(argv[2]);
100 : }
101 :
102 4 : return 0;
103 12 : }
104 :
105 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|