当前位置: 首页>>代码示例>>C++>>正文


C++ MyString::sprintf方法代码示例

本文整理汇总了C++中MyString::sprintf方法的典型用法代码示例。如果您正苦于以下问题:C++ MyString::sprintf方法的具体用法?C++ MyString::sprintf怎么用?C++ MyString::sprintf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MyString的用法示例。


在下文中一共展示了MyString::sprintf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: sprint

void AdNameHashKey::sprint (MyString &s)
{
	if (ip_addr.Length() )
		s.sprintf( "< %s , %s >", name.Value(), ip_addr.Value() );
	else
		s.sprintf( "< %s >", name.Value() );
}
开发者ID:,项目名称:,代码行数:7,代码来源:

示例2: dup

int
main(int, char* argv[])
{
	MyString err;

	// dup FD 0 since well will later replace FD 0 with the job's stdin
	//
	int sock_fd = dup(0);
	if (sock_fd == -1) {
		err.sprintf("dup error on FD 0: %s", strerror(errno));
		full_write(0, err.Value(), err.Length() + 1);
		exit(1);
	}

	// set up an Env object that we'll use for the job. we'll initialize
	// it with the environment that Condor sends us then merge on top of
	// that the environment that glexec prepared for us
	//
	Env env;
	char* env_buf = read_env(sock_fd);
	MyString merge_err;
	if (!env.MergeFromV2Raw(env_buf, &merge_err)) {
		err.sprintf("Env::MergeFromV2Raw error: %s", merge_err.Value());
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}
	env.MergeFrom(environ);
	delete[] env_buf;

	// now receive an FD on our stdin (which is a UNIX domain socket)
	// that we'll use as the job's stdin
	//
	int job_fd = read_fd(sock_fd);
	if (dup2(job_fd, 0) == -1) {
		err.sprintf("dup2 to FD 0 error: %s", strerror(errno));
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}
	close(job_fd);
	if (fcntl(sock_fd, F_SETFD, FD_CLOEXEC) == -1) {
		err.sprintf("fcntl error setting close-on-exec: %s",
		            strerror(errno));
		full_write(sock_fd, err.Value(), err.Length() + 1);
		exit(1);
	}

	// now we can exec the job. for arguments, we shift this wrappers
	// arguments by one. similarly, the job's executable path is taken
	// as our argv[1]
	//
	char** envp = env.getStringArray();
	execve(argv[1], &argv[1], envp);
	err.sprintf("execve error: %s", strerror(errno));
	full_write(sock_fd, err.Value(), err.Length() + 1);
	exit(1);
}
开发者ID:,项目名称:,代码行数:56,代码来源:

示例3: Unpublish

void stats_recent_counter_timer::Unpublish(ClassAd & ad, const char * pattr) const
{
   ad.Delete(pattr);
   MyString attr;
   attr.sprintf("Recent%s",pattr);
   ad.Delete(attr.Value());
   attr.sprintf("Recent%sRuntime",pattr);
   ad.Delete(attr.Value());
   ad.Delete(attr.Value()+6); // +6 to skip "Recent" prefix
}
开发者ID:,项目名称:,代码行数:10,代码来源:

示例4: strnewp

bool
Env::SetEnvWithErrorMessage( const char *nameValueExpr, MyString *error_msg )
{
	char *expr, *delim;
	int retval;

	if( nameValueExpr == NULL || nameValueExpr[0] == '\0' ) {
		return false;
	}

	// make a copy of nameValueExpr for modifying
	expr = strnewp( nameValueExpr );
	ASSERT( expr );

	// find the delimiter
	delim = strchr( expr, '=' );

	if(delim == NULL && strstr(expr,"$$")) {
		// This environment entry is an unexpanded $$() macro.
		// We just want to keep it in the environment verbatim.
		SetEnv(expr,NO_ENVIRONMENT_VALUE);
		delete[] expr;
		return true;
	}

	// fail if either name or delim is missing
	if( expr == delim || delim == NULL ) {
		if(error_msg) {
			MyString msg;
			if(delim == NULL) {
				msg.sprintf(
				  "ERROR: Missing '=' after environment variable '%s'.",
				  nameValueExpr);
			}
			else {
				msg.sprintf("ERROR: missing variable in '%s'.",expr);
			}
			AddErrorMessage(msg.Value(),error_msg);
		}
		delete[] expr;
		return false;
	}

	// overwrite delim with '\0' so we have two valid strings
	*delim = '\0';

	// do the deed
	retval = SetEnv( expr, delim + 1 );
	delete[] expr;
	return retval;
}
开发者ID:,项目名称:,代码行数:51,代码来源:

示例5: sizeof

void
IpVerify::AuthEntryToString(const in6_addr & host, const char * user, perm_mask_t mask, MyString &result)
{
		// every address will be seen as IPv6 format. should do something
		// to print IPv4 address neatly.
	char buf[INET6_ADDRSTRLEN];
	memset((void*)buf, 0, sizeof(buf));
	uint32_t* addr = (uint32_t*)&host;
		// checks if IPv4-mapped-IPv6 address
	
	const char* ret = NULL;
	if (addr[0] == 0 && addr[1] == 0 && addr[2] == htonl(0xffff)) {
		ret = inet_ntop(AF_INET, (const void*)&addr[3], buf, sizeof(buf));
	} else {
		ret = inet_ntop(AF_INET6, &host, buf, sizeof(buf));
	}

#ifndef WIN32
	if (!ret) {
		dprintf(D_HOSTNAME, "IP address conversion failed, errno = %d\n",
				errno);
	}
#endif

	MyString mask_str;
	PermMaskToString( mask, mask_str );
	result.sprintf("%s/%s: %s", /* NOTE: this does not need a '\n', all the call sites add one. */
			user ? user : "(null)",
			buf,
			mask_str.Value() );
}
开发者ID:,项目名称:,代码行数:31,代码来源:

示例6:

bool
Job::CanAddParent( Job* parent, MyString &whynot )
{
	if( !parent ) {
		whynot = "parent == NULL";
		return false;
	}
	if(GetFinal()) {
		whynot = "Tried to add a parent to a Final node";
		return false;
	}

		// we don't currently allow a new parent to be added to a
		// child that has already been started (unless the parent is
		// already marked STATUS_DONE, e.g., when rebuilding from a
		// rescue DAG) -- but this restriction might be lifted in the
		// future once we figure out the right way for the DAG to
		// respond...
	if( _Status != STATUS_READY && parent->GetStatus() != STATUS_DONE ) {
		whynot.sprintf( "%s child may not be given a new %s parent",
						this->GetStatusName(), parent->GetStatusName() );
		return false;
	}
	whynot = "n/a";
	return true;
}
开发者ID:,项目名称:,代码行数:26,代码来源:

示例7: assigned

bool
Job::AddScript( bool post, const char *cmd, MyString &whynot )
{
	if( !cmd || strcmp( cmd, "" ) == 0 ) {
		whynot = "missing script name";
		return false;
	}
	if( post ? _scriptPost : _scriptPre ) {
		whynot.sprintf( "%s script already assigned (%s)",
						post ? "POST" : "PRE", GetPreScriptName() );
		return false;
	}
	Script* script = new Script( post, cmd, this );
	if( !script ) {
		dprintf( D_ALWAYS, "ERROR: out of memory!\n" );
			// we already know we're out of memory, so filling in
			// whynot will likely fail, but give it a shot...
		whynot = "out of memory!";
		return false;
	}
	if( post ) {
		_scriptPost = script;
	}
	else {
		_scriptPre = script;
	}
	whynot = "n/a";
	return true;
}
开发者ID:,项目名称:,代码行数:29,代码来源:

示例8: if

bool
ArgList::V1WackedToV1Raw(char const *v1_input,MyString *v1_raw,MyString *errmsg)
{
	if(!v1_input) return true;
	ASSERT(v1_raw);
	ASSERT(!IsV2QuotedString(v1_input));

	while(*v1_input) {
		if(*v1_input == '"') {
			if(errmsg) {
				MyString msg;
				msg.sprintf("Found illegal unescaped double-quote: %s",v1_input);
				AddErrorMessage(msg.Value(),errmsg);
			}
			return false;
		}
		else if(v1_input[0] == '\\' && v1_input[1] == '"') {
			// Escaped double-quote.
			v1_input++;
			(*v1_raw) += *(v1_input++);
		}
		else {
			(*v1_raw) += *(v1_input++);
		}
	}
	return true;
}
开发者ID:,项目名称:,代码行数:27,代码来源:

示例9: dprintf

bool
VMGahpServer::write_line(const char *command)
{
    if( m_is_initialized == false ) {
        return false;
    }

    if( !command || m_vmgahp_writefd == -1 ) {
        return false;
    }

    if( daemonCore->Write_Pipe(m_vmgahp_writefd,command,strlen(command)) <= 0 ) {
        dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", command);
        return false;
    }

    if( daemonCore->Write_Pipe(m_vmgahp_writefd,"\r\n",2) <= 0) {
        dprintf( D_ALWAYS, "VMGAHP write line(%s) Error\n", "\r\n");
        return false;
    }

    MyString debug;
    debug.sprintf( "'%s'", command );
    dprintf( D_FULLDEBUG, "VMGAHP[%d] <- %s\n", m_vmgahp_pid,
             debug.Value() );

    return true;
}
开发者ID:,项目名称:,代码行数:28,代码来源:

示例10: StartBatchStatus

DCloudResource::BatchStatusResult DCloudResource::StartBatchStatus()
{
	ASSERT(status_gahp);

	StringList instance_ids;
	StringList statuses;
	const char *instance_id;
	const char *status;

	int rc = status_gahp->dcloud_status_all( ResourceName(), m_username,
											 m_password, instance_ids,
											 statuses );
	if ( rc == GAHPCLIENT_COMMAND_PENDING ) {
		return BSR_PENDING;
	}
	if ( rc != 0 ) {
		dprintf( D_ALWAYS, "Error attempting a Deltacloud batch status query: %s\n", status_gahp->getErrorString() );
		return BSR_ERROR;
	}

	DCloudJob *next_job;
	List<DCloudJob> my_jobs;
	registeredJobs.Rewind();
	while ( (next_job = (DCloudJob *)registeredJobs.Next()) ) {
		my_jobs.Insert( next_job );
	}

	instance_ids.rewind();
	statuses.rewind();
	while ( (instance_id = instance_ids.next()) &&
			(status = statuses.next()) ) {

		MyString hashname;
		hashname.sprintf( "%s#%s", ResourceName(), instance_id );
		DCloudJob *job = NULL;

		// TODO We can get rid of the hashtable.
		rc = DCloudJob::JobsByInstanceId.lookup(
										HashKey( hashname.Value() ), job );
		if ( rc != 0 ) {
			// Job not found. Probably okay; we might see jobs
			// submitted via other means, or jobs we've abandoned.
			dprintf( D_FULLDEBUG, "Job %s on remote host is unknown. Skipping.\n", hashname.Value() );
			continue;
		}
		ASSERT( job );

		job->StatusUpdate( status );

		my_jobs.Delete( job );
	}

	my_jobs.Rewind();
	while ( (next_job = my_jobs.Next()) ) {
		next_job->StatusUpdate( NULL );
	}

	return BSR_DONE;
}
开发者ID:,项目名称:,代码行数:59,代码来源:

示例11: to_sinful

MyString condor_sockaddr::to_sinful() const
{
    MyString ret;
    char tmp[IP_STRING_BUF_SIZE];
    // if it is not ipv4 or ipv6, to_ip_string_ex will fail.
    if ( !to_ip_string_ex(tmp, IP_STRING_BUF_SIZE) )
        return ret;

    if (is_ipv4()) {
        ret.sprintf("<%s:%d>", tmp, ntohs(v4.sin_port));
    }
    else if (is_ipv6()) {
        ret.sprintf("<[%s]:%d>", tmp, ntohs(v6.sin6_port));
    }

    return ret;
}
开发者ID:,项目名称:,代码行数:17,代码来源:

示例12: ASSERT

static pid_t
privsep_launch_switchboard(const char* op, FILE*& in_fp, FILE*& err_fp)
{
    ASSERT(switchboard_path != NULL);
    ASSERT(switchboard_file != NULL);

    // create the pipes for communication with the switchboard
    //
    int child_in_fd;
    int child_err_fd;
    if (!privsep_create_pipes(in_fp, child_in_fd, err_fp, child_err_fd)) {
        return 0;
    }

    pid_t switchboard_pid = fork();
    if (switchboard_pid == -1) {
        dprintf(D_ALWAYS,
                "privsep_launch_switchboard: fork error: %s (%d)\n",
                strerror(errno),
                errno);
        return 0;
    }

    // in the parent, we just return back to the caller so they can
    // start sending commands to the switchboard's input pipe; but
    // make sure to close the clients sides of our pipes first
    //
    if (switchboard_pid != 0) {
        close(child_in_fd);
        close(child_err_fd);
        return switchboard_pid;
    }

    // in the child, we need to exec the switchboard binary with the
    // appropriate arguments
    //
    close(fileno(in_fp));
    close(fileno(err_fp));
    MyString cmd;
    ArgList arg_list;
    privsep_get_switchboard_command(op,
                                    child_in_fd,
                                    child_err_fd,
                                    cmd,
                                    arg_list);
    execv(cmd.Value(), arg_list.GetStringArray());

    // exec failed; tell our parent using the error pipe that something
    // went wrong before exiting
    //
    MyString err;
    err.sprintf("exec error on %s: %s (%d)\n",
                cmd.Value(),
                strerror(errno),
                errno);
    write_error_code = write(child_err_fd, err.Value(), err.Length());
    _exit(1);
}
开发者ID:,项目名称:,代码行数:58,代码来源:

示例13: GetNextJobByConstraint

Manageable::status_t
SubmissionObject::GetJobSummaries ( Variant::List &jobs,
                            std::string &text )
{
	ClassAd *ad = NULL;
	MyString constraint;
	// id, timestamp (which?), command, args, ins, outs, state, message
	const char *ATTRS[] = {ATTR_CLUSTER_ID,
			ATTR_PROC_ID,
			ATTR_GLOBAL_JOB_ID,
			ATTR_Q_DATE,
			ATTR_ENTERED_CURRENT_STATUS,
			ATTR_JOB_STATUS,
			ATTR_JOB_CMD,
			ATTR_JOB_ARGUMENTS1,
			ATTR_JOB_ARGUMENTS2,
			ATTR_RELEASE_REASON,
			ATTR_HOLD_REASON,
			NULL
			};

	constraint.sprintf("%s == \"%s\"",
					   ATTR_JOB_SUBMISSION, this->m_name.c_str());

	dprintf(D_FULLDEBUG,"GetJobSummaries for submission: %s\n",constraint.Value());

	Variant::Map job;
	int init_scan = 1;
	while (NULL != (ad = GetNextJobByConstraint(constraint.Value(), init_scan))) {

		// debug
//		if (IsFulldebug(D_FULLDEBUG)) {
//			ad->dPrint(D_FULLDEBUG|D_NOHEADER);
//		}

		for (int i = 0; NULL != ATTRS[i]; i++) {
			if (!AddAttribute(*ad, ATTRS[i], job)) {
				dprintf(D_FULLDEBUG,"Warning: %s attribute not found for job of %s\n",ATTRS[i],constraint.Value());
			}
		}

		jobs.push_back(job);
		init_scan = 0;

		// debug
//		if (IsFulldebug(D_FULLDEBUG)) {
//			std::ostringstream oss;
//			oss << jobs;
//			dprintf(D_FULLDEBUG|D_NOHEADER, "%s\n",oss.str().c_str());
//		}

		FreeJobAd(ad);
		ad = NULL;
	}

	return STATUS_OK;
}
开发者ID:,项目名称:,代码行数:57,代码来源:

示例14: cpus

int *
OsProc::makeCpuAffinityMask(int slotId) {
	bool useAffinity = param_boolean("ENFORCE_CPU_AFFINITY", false);

	if (!useAffinity) {
		dprintf(D_FULLDEBUG, "ENFORCE_CPU_AFFINITY not true, not setting affinity\n");	
		return NULL;
	}

	// slotID of 0 means "no slot".  Punt.
	if (slotId < 1) {
		return NULL;
	}

	MyString affinityParam;

	affinityParam.sprintf("SLOT%d_CPU_AFFINITY", slotId);
	char *affinityParamResult = param(affinityParam.Value());

	if (affinityParamResult == NULL) {
		// No specific cpu, assume one-to-one mapping from slotid
		// to cpu affinity

		dprintf(D_FULLDEBUG, "Setting cpu affinity to %d\n", slotId - 1);	
		int *mask = (int *) malloc(sizeof(int) * 2);
		ASSERT( mask != NULL );
		mask[0] = 2;
		mask[1] = slotId - 1; // slots start at 1, cpus at 0
		return mask;
	}

	StringList cpus(affinityParamResult);

	if (cpus.number() < 1) {
		dprintf(D_ALWAYS, "Could not parse affinity string %s, not setting affinity\n", affinityParamResult);
		free(affinityParamResult);
		return NULL;
	}

	int *mask = (int *) malloc(sizeof(int) * (cpus.number() + 1));
	if ( ! mask)
		return mask;

	mask[0] = cpus.number() + 1;
	cpus.rewind();
	char *cpu;
	int index = 1;
	while ((cpu = cpus.next())) {
		mask[index++] = atoi(cpu);
	}

	free(affinityParamResult);
	return mask;
}
开发者ID:,项目名称:,代码行数:54,代码来源:

示例15: PublishUpdateAd

bool
OsProc::PublishUpdateAd( ClassAd* ad ) 
{
	dprintf( D_FULLDEBUG, "Inside OsProc::PublishUpdateAd()\n" );
	MyString buf;

	if (m_proc_exited) {
		buf.sprintf( "%s=\"Exited\"", ATTR_JOB_STATE );
	} else if( is_checkpointed ) {
		buf.sprintf( "%s=\"Checkpointed\"", ATTR_JOB_STATE );
	} else if( is_suspended ) {
		buf.sprintf( "%s=\"Suspended\"", ATTR_JOB_STATE );
	} else {
		buf.sprintf( "%s=\"Running\"", ATTR_JOB_STATE );
	}
	ad->Insert( buf.Value() );

	buf.sprintf( "%s=%d", ATTR_NUM_PIDS, num_pids );
	ad->Insert( buf.Value() );

	if (m_proc_exited) {
		if( dumped_core ) {
			buf.sprintf( "%s = True", ATTR_JOB_CORE_DUMPED );
			ad->Insert( buf.Value() );
		} // should we put in ATTR_JOB_CORE_DUMPED = false if not?
	}

	return UserProc::PublishUpdateAd( ad );
}
开发者ID:,项目名称:,代码行数:29,代码来源:


注:本文中的MyString::sprintf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。