本文整理汇总了C++中MyString::c_str方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::c_str方法的具体用法?C++ MyString::c_str怎么用?C++ MyString::c_str使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyString
的用法示例。
在下文中一共展示了MyString::c_str方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sentry
int
DockerAPI::stats(const std::string &container, uint64_t &memUsage, uint64_t &netIn, uint64_t &netOut) {
newstats(container, memUsage, netIn, netOut);
ArgList args;
if ( ! add_docker_arg(args))
return -1;
args.AppendArg( "stats" );
args.AppendArg( "--no-stream" );
args.AppendArg( container.c_str() );
MyString displayString;
TemporaryPrivSentry sentry(PRIV_ROOT);
args.GetArgsStringForLogging( & displayString );
dprintf( D_FULLDEBUG, "Attempting to run: %s\n", displayString.c_str() );
// Read from Docker's combined output and error streams.
FILE * dockerResults = my_popen( args, "r", 1 , 0, false);
if( dockerResults == NULL ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() );
return -2;
}
const int statLineSize = 256;
char header[statLineSize];
char data[statLineSize];
if( NULL == fgets( header, statLineSize, dockerResults ) ) {
my_pclose(dockerResults);
return -2;
}
if( NULL == fgets( data, statLineSize, dockerResults ) ) {
my_pclose(dockerResults);
return -2;
}
my_pclose(dockerResults);
dprintf(D_FULLDEBUG, "Docker stats data is:\n%s\n", data);
// condor stats output looks like:
// Name cpu% mem usage/limit mem% net i/o block i/o
// container 0.00% 0 B / 0 B 0.00% 0 B / 0 B 0 B / 0 B
//
char memUsageUnit[2];
char netInUnit[2];
char netOutUnit[2];
double memRaw, netInRaw, netOutRaw;
int matches = sscanf(data, "%*s %*g%% %lg %s / %*g %*s %*g%% %lg %s / %lg %s", &memRaw, &memUsageUnit[0], &netInRaw, &netInUnit[0], &netOutRaw, &netOutUnit[0]);
if (matches < 6) {
return -2;
}
memUsage = convertUnits(memRaw, memUsageUnit);
netIn = convertUnits(netInRaw, netInUnit);
netOut = convertUnits(netOutRaw, netOutUnit);
dprintf(D_FULLDEBUG, "memUsage is %g (%s), net In is %g (%s), net Out is %g (%s)\n", memRaw, memUsageUnit, netInRaw, netInUnit, netOutRaw, netOutUnit);
return 0;
}
示例2: startCommand
bool
DCShadow::getUserCredential( const char* user, const char* domain, MyString& credential)
{
ReliSock reli_sock;
bool result;
// For now, if we have to ensure that the update gets
// there, we use a ReliSock (TCP).
reli_sock.timeout(20); // years of research... :)
if( ! reli_sock.connect(_addr) ) {
dprintf( D_ALWAYS, "getUserCredential: Failed to connect to shadow "
"(%s)\n", _addr );
return false;
}
result = startCommand( CREDD_GET_PASSWD, (Sock*)&reli_sock );
if( ! result ) {
dprintf( D_FULLDEBUG,
"Failed to send CREDD_GET_PASSWD command to shadow\n" );
return false;
}
// Enable encryption if available. If it's not available, our peer
// will close the connection.
reli_sock.set_crypto_mode(true);
MyString senduser = user;
MyString senddomain = domain;
MyString recvcredential;
if(!reli_sock.code(senduser)) {
dprintf( D_FULLDEBUG, "Failed to send user (%s) to shadow\n", senduser.c_str() );
return false;
}
if(!reli_sock.code(senddomain)) {
dprintf( D_FULLDEBUG, "Failed to send domain (%s) to shadow\n", senddomain.c_str() );
return false;
}
if(!reli_sock.end_of_message()) {
dprintf( D_FULLDEBUG, "Failed to send EOM to shadow\n" );
return false;
}
reli_sock.decode();
if(!reli_sock.code(recvcredential)) {
dprintf( D_FULLDEBUG, "Failed to receive credential from shadow\n");
return false;
}
if(!reli_sock.end_of_message()) {
dprintf( D_FULLDEBUG, "Failed to receive EOM from shadow\n");
return false;
}
credential = recvcredential;
return true;
}
示例3: version
//
// FIXME: We have a lot of boilerplate code in this function and file.
//
int DockerAPI::version( std::string & version, CondorError & /* err */ ) {
ArgList versionArgs;
if ( ! add_docker_arg(versionArgs))
return -1;
versionArgs.AppendArg( "-v" );
MyString displayString;
versionArgs.GetArgsStringForLogging( & displayString );
dprintf( D_FULLDEBUG, "Attempting to run: '%s'.\n", displayString.c_str() );
FILE * dockerResults = my_popen( versionArgs, "r", 1 , 0, false);
if( dockerResults == NULL ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() );
return -2;
}
char buffer[1024];
if( NULL == fgets( buffer, 1024, dockerResults ) ) {
if( errno ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), strerror( errno ), errno );
} else {
dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() );
}
my_pclose( dockerResults );
return -3;
}
if( NULL != fgets( buffer, 1024, dockerResults ) ) {
if( strstr( buffer, "Jansens" ) != NULL ) {
dprintf( D_ALWAYS | D_FAILURE, "The DOCKER configuration setting appears to point to OpenBox's docker. If you want to use Docker.IO, please set DOCKER appropriately in your configuration.\n" );
} else {
dprintf( D_ALWAYS | D_FAILURE, "Read more than one line (or a very long line) from '%s', which we think means it's not Docker. The (first line of the) trailing text was '%s'.\n", displayString.c_str(), buffer );
}
my_pclose( dockerResults );
return -5;
}
int exitCode = my_pclose( dockerResults );
if( exitCode != 0 ) {
dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, buffer );
return -4;
}
unsigned end = strlen(buffer) - 1;
if( buffer[end] == '\n' ) { buffer[end] = '\0'; }
version = buffer;
return 0;
}
示例4: testparse
// helper functions to test the parsing of config files and/or metaknobs
//
void testparse(int lineno, MACRO_SET & set, MACRO_EVAL_CONTEXT &ctx, MACRO_SOURCE & source, bool verbose, const char * tag, const char * params, const char * expected)
{
int ret = Parse_config_string(source, 0, params, set, ctx);
const char * hashout = NULL;
if (ret < 0) {
fprintf(stderr, "Failed %5d: test '%s' local=%s subsys=%s parse error %d\n",
lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : "", ret);
gmstr.clear();
hashout = NULL;
} else {
dump_macro_set(set, gmstr, "\t");
hashout = gmstr.c_str();
if (gmstr != expected) {
fprintf(stderr, "Failed %5d: test '%s' local=%s subsys=%s resulting hashtable does not match expected\n",
lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : "");
ret = -1;
} else if (verbose) {
fprintf(stdout, " OK %5d: test '%s' local=%s subsys=%s\n",
lineno, tag, ctx.localname ? ctx.localname : "", ctx.subsys ? ctx.subsys : "");
ret = 0;
}
}
if (verbose || ret) {
fprintf(ret ? stderr : stdout, "\t---- parse input %d ----\n%s", lineno, params);
if (hashout) fprintf(ret ? stderr : stdout, "\t---- resulting hash %d ----\n%s", lineno, hashout);
if (ret) fprintf(stderr, "\t---- expected hash %d ----\n%s", lineno, expected);
fprintf(ret ? stderr : stdout, "\t---- end %d ----\n\n", lineno);
}
clear_macro_set(set);
}
示例5: x_exit
void x_exit(int ret)
{
MyString str;
str.Format("Critical Error : %d",ret);
x_fatal_exit(str.c_str());
}
示例6: exec
void CommandCd::exec(VirtualDiskNode* vfs)
{
if (!vfs)
{
assert(0);
return;
}
if (m_path.isEmpty())
{
MyString pwd = vfs->pwd();
if (!pwd.endWith(_T("\\")))
{
pwd += _T("\\");
}
_tprintf(_T("%s\n"), pwd.c_str());
return;
}
if (!isNormalizedPath(m_path))
{
m_path = vfs->pathNormalize(m_path);
}
m_path = m_path.toLower();
if (!m_path.startWith(_T("c:")))
{
throw CommandException(_T("系统找不到指定的驱动器\n"));
}
if (!vfs->isDir(m_path))
{
throw CommandException(_T("系统找不到指定的目录\n"));
}
vfs->chdir(m_path);
return;
}
示例7:
void
CondorQuery::setDesiredAttrs(char const * const *attrs)
{
MyString val;
::join_args(attrs,&val);
setDesiredAttrs(val.c_str());
}
示例8: strerror
int
run_simple_docker_command(const std::string &command, const std::string &container,
CondorError &)
{
ArgList args;
if ( ! add_docker_arg(args))
return -1;
args.AppendArg( command );
args.AppendArg( container.c_str() );
MyString displayString;
args.GetArgsStringForLogging( & displayString );
dprintf( D_FULLDEBUG, "Attempting to run: %s\n", displayString.c_str() );
// Read from Docker's combined output and error streams.
FILE * dockerResults = my_popen( args, "r", 1 , 0, false);
if( dockerResults == NULL ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() );
return -2;
}
// On a success, Docker writes the containerID back out.
char buffer[1024];
if( NULL == fgets( buffer, 1024, dockerResults ) ) {
if( errno ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to read results from '%s': '%s' (%d)\n", displayString.c_str(), strerror( errno ), errno );
} else {
dprintf( D_ALWAYS | D_FAILURE, "'%s' returned nothing.\n", displayString.c_str() );
}
my_pclose( dockerResults );
return -3;
}
int length = strlen( buffer );
if( length < 1 || strncmp( buffer, container.c_str(), length - 1 ) != 0 ) {
dprintf( D_ALWAYS | D_FAILURE, "Docker %s failed, printing first few lines of output.\n", command.c_str() );
dprintf( D_ALWAYS | D_FAILURE, "%s", buffer );
while( NULL != fgets( buffer, 1024, dockerResults ) ) {
dprintf( D_ALWAYS | D_FAILURE, "%s", buffer );
}
my_pclose( dockerResults );
return -4;
}
my_pclose( dockerResults );
return 0;
}
示例9: detect
int DockerAPI::detect( CondorError & err ) {
// FIXME: Remove ::version() as a public API and return it from here,
// because there's no point in doing this twice.
std::string version;
if( DockerAPI::version( version, err ) != 0 ) {
dprintf( D_ALWAYS | D_FAILURE, "DockerAPI::detect() failed to detect the Docker version; assuming absent.\n" );
return -4;
}
ArgList infoArgs;
if ( ! add_docker_arg(infoArgs))
return -1;
infoArgs.AppendArg( "info" );
MyString displayString;
infoArgs.GetArgsStringForLogging( & displayString );
dprintf( D_FULLDEBUG, "Attempting to run: '%s'.\n", displayString.c_str() );
FILE * dockerResults = my_popen( infoArgs, "r", 1 , 0, false);
if( dockerResults == NULL ) {
dprintf( D_ALWAYS | D_FAILURE, "Failed to run '%s'.\n", displayString.c_str() );
return -2;
}
// Even if we don't care about the success output, the failure output
// can be handy for debugging...
char buffer[1024];
std::vector< std::string > output;
while( fgets( buffer, 1024, dockerResults ) != NULL ) {
unsigned end = strlen(buffer) - 1;
if( buffer[end] == '\n' ) { buffer[end] = '\0'; }
output.push_back( buffer );
}
for( unsigned i = 0; i < output.size(); ++i ) {
dprintf( D_FULLDEBUG, "[docker info] %s\n", output[i].c_str() );
}
int exitCode = my_pclose( dockerResults );
if( exitCode != 0 ) {
dprintf( D_ALWAYS, "'%s' did not exit successfully (code %d); the first line of output was '%s'.\n", displayString.c_str(), exitCode, output[0].c_str() );
return -3;
}
return 0;
}
示例10: outputInfo
extern "C" int outputInfo(const char* format,...)
{
va_list argptr;
va_start( argptr, format );
MyString st;
st.FormatV(format,argptr);
va_end(argptr);
puts(st.c_str());
return 1;
}
示例11: deleteDownloadDirectory
void CDownload::deleteDownloadDirectory()
{
// détruit le répertoire de téléchargement
MyString dir;
dir = getPersistentPath();
dir += ACTIVEGS_DIRECTORY_SEPARATOR;
dir += activegsdownloaddir;
deleteDirectory(dir.c_str(),1);
}
示例12: x_alert
void x_alert(const char* format,...)
{
MyString theAlert;
va_list argptr;
va_start( argptr, format );
theAlert.FormatV(format,argptr);
va_end(argptr);
x_display_alert(0,"ActiveGS Warning",theAlert.c_str());
}
示例13: retrieveLocalFile
long CDownload::retrieveLocalFile(const MYCHAR* _url,int _order,MyString& _path, MyString& _short)
{
MyString url = _url;
MyString ext(getext(url));
if (!ext.CompareNoCase("zip"))
{
if (!retrieveZippedFile(url,_order,_path,_short))
{
if (!unzipFile(url,url))
{
// unzip failed...
outputInfo("unzip failed (%s)\n",_url);
return 0;
}
if (!retrieveZippedFile(url,_order,_path,_short))
{
outputInfo("could not find zip (%s)\n",_url);
return 0;
}
}
}
else
{
_path = url;
_short = getfile(url);
}
FILE* f = fopen(_path.c_str(),"rb");
if (f)
{
/*int err =*/ fseek(f,0,SEEK_END);
long size = ftell(f);
fclose(f);
return size;
}
else
{
outputInfo("could not find file (%s)\n",_url);
::showStatus("Failed to load %s",getfile(_url));
return 0;
}
}
示例14: listDirRecursive
void CommandDir::listDirRecursive(const MyString& path, VirtualDiskNode* vfs, bool only_dir /*= false*/)
{
_tprintf(_T(" %s 的目录\n\n"), path.c_str());
listDir(path, vfs, only_dir);
DirHandler dir_handler = vfs->openDir(path);
for (DirIterator iter = dir_handler.getIterator(); !iter.isDone(); iter.next())
{
state s = iter.getItem();
if (s.type == DIR_TYPE && !s.name.startWith(_T(".")))
{
listDirRecursive(s.path, vfs, only_dir);
}
}
}
示例15: showStatus
void showStatus(const MYCHAR* format,...)
{
va_list argptr;
va_start( argptr, format );
MyString st;
st.FormatV(format,argptr);
va_end(argptr);
// outputInfoInternal(st.c_str());
CEmulator* emu = CEmulator::theEmulator;
if (emu)
emu->showStatus(st.c_str());
}