1 // Copyright 2014 The Android Open Source Project 2 // 3 // This software is licensed under the terms of the GNU General Public 4 // License version 2, as published by the Free Software Foundation, and 5 // may be copied, distributed, and modified under those terms. 6 // 7 // This program is distributed in the hope that it will be useful, 8 // but WITHOUT ANY WARRANTY; without even the implied warranty of 9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 // GNU General Public License for more details. 11 12 #ifndef ANDROID_UTILS_WIN32_CMDLINE_QUOTE_H 13 #define ANDROID_UTILS_WIN32_CMDLINE_QUOTE_H 14 15 #include "android/utils/compiler.h" 16 17 ANDROID_BEGIN_HEADER 18 19 // Quote a given command-line command or parameter so that it can be 20 // sent to _execv() on Windows, and be received properly by the new 21 // process. 22 // 23 // This is necessary to work-around an annoying issue on Windows, where 24 // spawn() / exec() functions are mere wrappers around CreateProcess, which 25 // always pass the command-line as a _single_ string made of the simple 26 // concatenations of their arguments, while the new process will typically 27 // use CommandLineToArgv to convert it into a list of command-line arguments, 28 // expected the values to be quoted properly. 29 // 30 // For more details about this mess, read the MSDN blog post named 31 // "Everyone quotes arguments the wrong way". 32 // 33 // |param| is an input string, that may contain spaces, quotes or backslashes. 34 // The function returns a new heap-allocated function that contains a version 35 // of |param| that can be decoded properly by CommandLineToArgv(). The caller 36 // must free the string with android_free() or AFREE(). 37 char* win32_cmdline_quote(const char* param); 38 39 ANDROID_END_HEADER 40 41 #endif // ANDROID_UTILS_WIN32_CMDLINE_QUOTE_H 42