Created
November 6, 2016 11:55
-
-
Save congzhangzh/5141f1c4de4e7ac85d6f8d6a630207e7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern "C" int self_main(int argc, char**argv) | |
{ | |
//char cmdline[1024]={}; | |
std::string cmdLine; | |
//std::getline(std::fstream("/proc/self/cmdline", std::ios::binary|std::ios::in), cmdLine); | |
std::getline(std::fstream("/proc/self/cmdline", std::ios::in), cmdLine); | |
std::string::size_type pos=0; | |
std::string oldStr; | |
oldStr.resize(1); | |
oldStr[0]='\0'; | |
std::string newStr=" "; | |
while((pos=cmdLine.find(oldStr,pos))!=std::string::npos) | |
{ | |
cmdLine.replace(pos,oldStr.length(), newStr); | |
pos+=oldStr.length(); | |
} | |
//cmdLine.replace(std::string("\0"),std::string(" ")); | |
auto strStream=std::stringstream(cmdLine); | |
std::vector<std::string> tokens{std::istream_iterator<std::string>(strStream), | |
std::istream_iterator<std::string>()}; | |
std::vector<char*> tokenToken(tokens.size()); | |
std::transform( | |
std::begin(tokens), | |
std::end(tokens), | |
std::begin(tokenToken), | |
[](const std::string& tmpStr)-> char * { | |
return const_cast<char* >(tmpStr.data()); | |
}); | |
argc=tokenToken.size(); | |
argv=tokenToken.data(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment