• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ snprintf函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中snprintf函数的典型用法代码示例。如果您正苦于以下问题:C++ snprintf函数的具体用法?C++ snprintf怎么用?C++ snprintf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: LALGenerateEllipticSpinOrbitCW


//.........这里部分代码省略.........
  /* Allocate output structures. */
  if ( ( output->a = (REAL4TimeVectorSeries *)
	 LALMalloc( sizeof(REAL4TimeVectorSeries) ) ) == NULL ) {
    ABORT( stat, GENERATESPINORBITCWH_EMEM,
	   GENERATESPINORBITCWH_MSGEMEM );
  }
  memset( output->a, 0, sizeof(REAL4TimeVectorSeries) );
  if ( ( output->f = (REAL4TimeSeries *)
	 LALMalloc( sizeof(REAL4TimeSeries) ) ) == NULL ) {
    LALFree( output->a ); output->a = NULL;
    ABORT( stat, GENERATESPINORBITCWH_EMEM,
	   GENERATESPINORBITCWH_MSGEMEM );
  }
  memset( output->f, 0, sizeof(REAL4TimeSeries) );
  if ( ( output->phi = (REAL8TimeSeries *)
	 LALMalloc( sizeof(REAL8TimeSeries) ) ) == NULL ) {
    LALFree( output->a ); output->a = NULL;
    LALFree( output->f ); output->f = NULL;
    ABORT( stat, GENERATESPINORBITCWH_EMEM,
	   GENERATESPINORBITCWH_MSGEMEM );
  }
  memset( output->phi, 0, sizeof(REAL8TimeSeries) );

  /* Set output structure metadata fields. */
  output->position = params->position;
  output->psi = params->psi;
  output->a->epoch = output->f->epoch = output->phi->epoch
    = params->epoch;
  output->a->deltaT = n*params->deltaT;
  output->f->deltaT = output->phi->deltaT = params->deltaT;
  output->a->sampleUnits = lalStrainUnit;
  output->f->sampleUnits = lalHertzUnit;
  output->phi->sampleUnits = lalDimensionlessUnit;
  snprintf( output->a->name, LALNameLength, "CW amplitudes" );
  snprintf( output->f->name, LALNameLength, "CW frequency" );
  snprintf( output->phi->name, LALNameLength, "CW phase" );

  /* Allocate phase and frequency arrays. */
  LALSCreateVector( stat->statusPtr, &( output->f->data ), n );
  BEGINFAIL( stat ) {
    LALFree( output->a );   output->a = NULL;
    LALFree( output->f );   output->f = NULL;
    LALFree( output->phi ); output->phi = NULL;
  } ENDFAIL( stat );
  LALDCreateVector( stat->statusPtr, &( output->phi->data ), n );
  BEGINFAIL( stat ) {
    TRY( LALSDestroyVector( stat->statusPtr, &( output->f->data ) ),
	 stat );
    LALFree( output->a );   output->a = NULL;
    LALFree( output->f );   output->f = NULL;
    LALFree( output->phi ); output->phi = NULL;
  } ENDFAIL( stat );

  /* Allocate and fill amplitude array. */
  {
    CreateVectorSequenceIn in; /* input to create output->a */
    in.length = 2;
    in.vectorLength = 2;
    LALSCreateVectorSequence( stat->statusPtr, &(output->a->data), &in );
    BEGINFAIL( stat ) {
      TRY( LALSDestroyVector( stat->statusPtr, &( output->f->data ) ),
	   stat );
      TRY( LALDDestroyVector( stat->statusPtr, &( output->phi->data ) ),
	   stat );
      LALFree( output->a );   output->a = NULL;
      LALFree( output->f );   output->f = NULL;
开发者ID:smirshekari,项目名称:lalsuite,代码行数:67,代码来源:GenerateEllipticSpinOrbitCW.c


示例2: snprintf

char *get_running_state_fname(const char *ve_private, char *buf, int size)
{
	snprintf(buf, size, "%s/.running", ve_private);

	return buf;
}
开发者ID:OpenVZ,项目名称:libvzctl,代码行数:6,代码来源:vz.c


示例3: vzctl2_env_register

/** Register Container
 * @param path		Container private data root
 * @param param		struct vzctl_reg_param
 * @param flags		registration flags
 * @return		veid or -1 in case error
 */
int vzctl2_env_register(const char *path, struct vzctl_reg_param *param, int flags)
{
	char buf[PATH_MAX];
	char veconf[STR_SIZE];
	char path_r[PATH_MAX];
	struct stat st;
	int ret, err;
	struct vzctl_env_handle *h;
	FILE *fp;
	char ve_host[STR_SIZE];
	char host[STR_SIZE];
	int owner_check_res;
	int on_pcs, on_shared;
	int ha_resource_added = 0;
	int ha_enable = 0;
	const char *data, *name;
	ctid_t ctid = {};
	ctid_t uuid = {};

	/* preserve compatibility
	 * VZ_REG_SKIP_HA_CLUSTER is alias for VZ_REG_SKIP_CLUSTER
	 */
	if (flags & VZ_REG_SKIP_HA_CLUSTER)
		flags |= VZ_REG_SKIP_CLUSTER;

	if (stat(path, &st) != 0)
		return vzctl_err(-1, errno, "Unable to stat %s", path);

	if (realpath(path, path_r) == NULL)
		return vzctl_err(-1, errno, "Failed to get realpath %s", path);

	ret = vzctl2_env_layout_version(path_r);
	if (ret == -1) {
		return -1;
	} else if (ret < VZCTL_LAYOUT_4)
		return vzctl_err(-1, 0, "Warning: Container in old data format,"
				" registration skipped.");

	snprintf(veconf, sizeof(veconf), "%s/" VZCTL_VE_CONF, path_r);
	if (stat(veconf, &st)) {
		logger(-1, 0, "Error: Broken Container, no %s file found", veconf);
		return -1;
	}

	h = vzctl2_env_open_conf(param->ctid, veconf, 0, &err);
	if (h == NULL)
		return -1;

	data = param->uuid;
	/* get UUID from config if not specified */
	if (data == NULL)
		vzctl2_env_get_param(h, "UUID", &data);

	if (get_cid_uuid_pair(param->ctid, data, ctid, uuid))
		goto err;

	owner_check_res = vzctl_check_owner_quiet(
			path_r, host, sizeof(host), ve_host, sizeof(ve_host));
	on_pcs = (is_pcs(path_r) == 1);
	on_shared = (is_shared_fs(path_r) == 1);

        if (vzctl2_env_get_param(h, "HA_ENABLE", &data) == 0 && data != NULL)
                ha_enable = yesno2id(data);

	if (on_pcs && ha_enable != VZCTL_PARAM_OFF &&
			check_external_disk(path_r, h->env_param->disk) &&
			shaman_is_configured())
	{
		logger(-1, 0, "Containers with external disks cannot be"
				" registered in a High Availability cluster");
		goto err;
	}

	if (!(flags & VZ_REG_FORCE)) {
		/* ignore renew option for pstorage (https://jira.sw.ru/browse/PSBM-16819) */
		if (on_pcs)
			flags &= ~VZ_REG_RENEW;

		if (!(flags & VZ_REG_RENEW) && owner_check_res) {
			if (owner_check_res == VZCTL_E_ENV_MANAGE_DISABLED) {
				logger(-1, 0, "Owner check failed on the server %s;"
					" Container is registered for %s", host, ve_host);
				if (on_pcs)
					logger(0, 0,
					"Failed to register the Container/virtual machine. "
					"You can force the registration, but this will revoke "
					"all access to the Container from the original server.");
			}
			goto err;
		}

		if (validate_eid(h, &st, ctid))
			goto err;
	} else if ((owner_check_res == VZCTL_E_ENV_MANAGE_DISABLED) && on_shared) {
//.........这里部分代码省略.........
开发者ID:OpenVZ,项目名称:libvzctl,代码行数:101,代码来源:vz.c


示例4: CGPS9_23LogPosition

void CGPS9_23LogPosition (uint8_t vl_index, uint32_t Status_Code, s_GN_GPS_Nav_Data *pl_nav_data_to_use)
{
#if defined( CMCC_LOGGING_ENABLE ) && defined( AGPS_UP_FTR )
    int8_t Session_Start[20], Session_End[20];

    switch( Status_Code )
    {
        case CGPS_SUPL_CMCC_AGPS_SESSION_STARTED:
           sprintf( (char*)Session_Start , "%d" , 0 );
           GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_AGPS_SESSION_STARTED , Session_Start , "session starts");
        break;

        case CGPS_SUPL_CMCC_REPONSE_TIMEOUT_CODE:
            if (pl_nav_data_to_use != NULL)
            {
                if(pl_nav_data_to_use->Valid_SingleFix || pl_nav_data_to_use->Valid_SingleFix)
                {
                    /*we have a fix but don't reach the quality*/
                    sprintf( s_CmccLog, "%i, %04d%02d%02d%02d%02d%02d.%03d, %f, %f, %f, %f, # Position(Timestamp, lat, lon, orientation, height)  time to fix : %ld ms",
                        s_CgpsSupl[vl_index].v_GPSHandle, pl_nav_data_to_use->Year, pl_nav_data_to_use->Month,
                        pl_nav_data_to_use->Day, pl_nav_data_to_use->Hours, pl_nav_data_to_use->Minutes,
                        pl_nav_data_to_use->Seconds, pl_nav_data_to_use->Milliseconds,
                        pl_nav_data_to_use->Latitude, pl_nav_data_to_use->Longitude,
                        pl_nav_data_to_use->CourseOverGround, pl_nav_data_to_use->Altitude_MSL,
                        GN_GPS_Get_OS_Time_ms()-s_CgpsNaf[vl_index].v_RegisterTime);

                    GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_REPONSE_TIMEOUT_CODE, (char*)s_CmccLog, CGPS_SUPL_CMCC_POSITION_QUALITY_NOT_REACHED_STRING);
                }
                else
                {
                    /*no fix*/
                    snprintf( s_CmccLog,CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%i",s_CgpsSupl[vl_index].v_GPSHandle);
                    GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_REPONSE_TIMEOUT_CODE, (char*)s_CmccLog, CGPS_SUPL_CMCC_CANNOT_PRODUCE_POSITION_WITHIN_RESP_TIME_STRING);
                }
            }
            else
            {
                sprintf( s_CmccLog, "%i, %04d%02d%02d%02d%02d%02d.%03d, %f, %f, %f, %f, # Position(Timestamp, lat, lon, orientation, height)  time to fix : %ld ms",
                    s_CgpsSupl[vl_index].v_GPSHandle, vg_Nav_Data.Year, vg_Nav_Data.Month,
                    vg_Nav_Data.Day, vg_Nav_Data.Hours, vg_Nav_Data.Minutes,
                    vg_Nav_Data.Seconds, vg_Nav_Data.Milliseconds,
                    vg_Nav_Data.Latitude, vg_Nav_Data.Longitude,
                    vg_Nav_Data.CourseOverGround, vg_Nav_Data.Altitude_MSL,
                    GN_GPS_Get_OS_Time_ms()-s_CgpsSupl[vl_index].v_RegisterTime);
                GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_REPONSE_TIMEOUT_CODE, (char*)s_CmccLog, NULL);
            }
        break;

        case CGPS_SUPL_CMCC_POSITION_RESULT_CODE:
            if (pl_nav_data_to_use != NULL)
            {
                sprintf( s_CmccLog, "%i, %04d%02d%02d%02d%02d%02d.%03d, %f, %f, %f, %f, # Position(Timestamp, lat, lon, orientation, height)  time to fix : %ld ms",
                    s_CgpsSupl[vl_index].v_GPSHandle, pl_nav_data_to_use->Year, pl_nav_data_to_use->Month,
                    pl_nav_data_to_use->Day, pl_nav_data_to_use->Hours, pl_nav_data_to_use->Minutes,
                    pl_nav_data_to_use->Seconds, pl_nav_data_to_use->Milliseconds,
                    pl_nav_data_to_use->Latitude, pl_nav_data_to_use->Longitude,
                    pl_nav_data_to_use->CourseOverGround, pl_nav_data_to_use->Altitude_MSL,
                    GN_GPS_Get_OS_Time_ms()-s_CgpsNaf[vl_index].v_RegisterTime);

                GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_POSITION_RESULT_CODE, (char*)s_CmccLog, NULL);
            }
        break;

        case CGPS_SUPL_CMCC_NETWORKCONNECTION_CODE:
            snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%i",s_CgpsSupl[vl_index].v_GPSHandle);
            GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_NETWORKCONNECTION_CODE,(char*)s_CmccLog,CGPS_SUPL_CMCC_NETWORKCONNECTION_STRING);
        break;

        case CGPS_SUPL_CMCC_NO_NETWORKCONNECTION_CODE:
            if (vl_index == 0xFF)
            {
                snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%x", 0xFFFFFFFF);
                GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_NO_NETWORKCONNECTION_CODE, (char*)s_CmccLog, CGPS_SUPL_CMCC_AUTONOMOUS_SET_STRING);
            }
            else
            {
                snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1,"%i",s_CgpsSupl[vl_index].v_GPSHandle);
                GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_NO_NETWORKCONNECTION_CODE, (char*)s_CmccLog, CGPS_SUPL_CMCC_NO_NETWORKCONNECTION_STRING);
            }
        break;

        case CGPS_SUPL_CMCC_NETWORKCONNECTION_FAILURE_CODE:
            snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%i",s_CgpsSupl[vl_index].v_GPSHandle);
            GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_NETWORKCONNECTION_FAILURE_CODE, (char*)s_CmccLog, CGPS_SUPL_CMCC_NETWORKCONNECTION_FAILURE_STRING);
        break;

        case CGPS_SUPL_CMCC_SERVERCONNECTION_CODE:
            snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%i",s_CgpsSupl[vl_index].v_GPSHandle);
            GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_SERVERCONNECTION_CODE,(char*)s_CmccLog,CGPS_SUPL_CMCC_SERVERCONNECTION_STRING);
        break;

        case CGPS_SUPL_CMCC_SERVERCONNECTION_FAILURE_CODE:
            snprintf(s_CmccLog, CGPS_SUPL_CMCC_STRING_MAX_LENGHT-1, "%i",s_CgpsSupl[vl_index].v_GPSHandle);
            GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_SERVERCONNECTION_FAILURE_CODE,(char*)s_CmccLog,CGPS_SUPL_CMCC_SERVERCONNECTION_FAILURE_STRING);
        break;

        case CGPS_SUPL_CMCC_AGPS_SESSION_ENDED:
           sprintf( (char*)Session_End , "%d" , 0 );
           GN_SUPL_Write_Event_Log_CMCC(CGPS_SUPL_CMCC_AGPS_SESSION_STARTED , Session_End , "session ends");
        break;
//.........这里部分代码省略.........
开发者ID:DevSwift,项目名称:android_hardware_ste-sony,代码行数:101,代码来源:cgps9testMode.c


示例5: T

/*********************************************************************
CREATE TABLE T(
 	c1 VARCHAR(n),
       	c2 INT NOT NULL,
       	c3 FLOAT,
       	c4 DOUBLE,
       	c5 BLOB,
	c6 DECIMAL,
	PK(c1));  */
static
ib_err_t
create_table(
/*=========*/
	const char*	dbname,			/*!< in: database name */
	const char*	name)			/*!< in: table name */
{
	ib_trx_t	ib_trx;
	ib_id_t		table_id = 0;
	ib_err_t	err = DB_SUCCESS;
	ib_tbl_sch_t	ib_tbl_sch = NULL;
	ib_idx_sch_t	ib_idx_sch = NULL;
	char		table_name[IB_MAX_TABLE_NAME_LEN];

#ifdef __WIN__
	sprintf(table_name, "%s/%s", dbname, name);
#else
	snprintf(table_name, sizeof(table_name), "%s/%s", dbname, name);
#endif

	/* Pass a table page size of 0, ie., use default page size. */
	err = ib_table_schema_create(
		table_name, &ib_tbl_sch, IB_TBL_COMPACT, 0);

	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c1", IB_VARCHAR, IB_COL_NONE, 0, 10);

	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c2", IB_INT, IB_COL_NOT_NULL, 0, sizeof(ib_u32_t));
	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c3", IB_FLOAT, IB_COL_NONE, 0, sizeof(float));
	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c4", IB_DOUBLE, IB_COL_NONE, 0, sizeof(double));
	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c5", IB_BLOB, IB_COL_NONE, 0, 0);
	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_col(
		ib_tbl_sch, "c6", IB_DECIMAL, IB_COL_NONE, 0, 0);
	assert(err == DB_SUCCESS);

	err = ib_table_schema_add_index(ib_tbl_sch, "PRIMARY", &ib_idx_sch);
	assert(err == DB_SUCCESS);

	/* Set prefix length to 0. */
	err = ib_index_schema_add_col( ib_idx_sch, "c1", 0);
	assert(err == DB_SUCCESS);

	err = ib_index_schema_set_clustered(ib_idx_sch);
	assert(err == DB_SUCCESS);

	/* create table */
	ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ);
	err = ib_schema_lock_exclusive(ib_trx);
	assert(err == DB_SUCCESS);

	err = ib_table_create(ib_trx, ib_tbl_sch, &table_id);
	assert(err == DB_SUCCESS);

	err = ib_trx_commit(ib_trx);
	assert(err == DB_SUCCESS);

	if (ib_tbl_sch != NULL) {
		ib_table_schema_delete(ib_tbl_sch);
	}

	return(err);
}
开发者ID:toffaletti,项目名称:turtle,代码行数:87,代码来源:ib_types.c


示例6: dbg_mask_show

static ssize_t dbg_mask_show(struct device *d,
		struct device_attribute *attr, char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%d\n", data_msg_dbg_mask);
}
开发者ID:android-armv7a-belalang-tempur,项目名称:android_kernel_samsung_smdk4210-1,代码行数:5,代码来源:rmnet_usb_data.c


示例7: dm4_dive


//.........这里部分代码省略.........
	 */
	if (data[3])
		state->cur_dive->duration.seconds = atoi(data[3]);
	if (data[15])
		state->cur_dive->dc.duration.seconds = atoi(data[15]);

	/*
	 * TODO: the deviceid hash should be calculated here.
	 */
	settings_start(state);
	dc_settings_start(state);
	if (data[4])
		utf8_string(data[4], &state->cur_settings.dc.serial_nr);
	if (data[5])
		utf8_string(data[5], &state->cur_settings.dc.model);

	state->cur_settings.dc.deviceid = 0xffffffff;
	dc_settings_end(state);
	settings_end(state);

	if (data[6])
		state->cur_dive->dc.maxdepth.mm = lrint(strtod_flags(data[6], NULL, 0) * 1000);
	if (data[8])
		state->cur_dive->dc.airtemp.mkelvin = C_to_mkelvin(atoi(data[8]));
	if (data[9])
		state->cur_dive->dc.watertemp.mkelvin = C_to_mkelvin(atoi(data[9]));

	/*
	 * TODO: handle multiple cylinders
	 */
	cylinder_start(state);
	if (data[22] && atoi(data[22]) > 0)
		state->cur_dive->cylinder[state->cur_cylinder_index].start.mbar = atoi(data[22]);
	else if (data[10] && atoi(data[10]) > 0)
		state->cur_dive->cylinder[state->cur_cylinder_index].start.mbar = atoi(data[10]);
	if (data[23] && atoi(data[23]) > 0)
		state->cur_dive->cylinder[state->cur_cylinder_index].end.mbar = (atoi(data[23]));
	if (data[11] && atoi(data[11]) > 0)
		state->cur_dive->cylinder[state->cur_cylinder_index].end.mbar = (atoi(data[11]));
	if (data[12])
		state->cur_dive->cylinder[state->cur_cylinder_index].type.size.mliter = lrint((strtod_flags(data[12], NULL, 0)) * 1000);
	if (data[13])
		state->cur_dive->cylinder[state->cur_cylinder_index].type.workingpressure.mbar = (atoi(data[13]));
	if (data[20])
		state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.o2.permille = atoi(data[20]) * 10;
	if (data[21])
		state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.he.permille = atoi(data[21]) * 10;
	cylinder_end(state);

	if (data[14])
		state->cur_dive->dc.surface_pressure.mbar = (atoi(data[14]) * 1000);

	interval = data[16] ? atoi(data[16]) : 0;
	profileBlob = (float *)data[17];
	tempBlob = (unsigned char *)data[18];
	pressureBlob = (int *)data[19];
	for (i = 0; interval && i * interval < state->cur_dive->duration.seconds; i++) {
		sample_start(state);
		state->cur_sample->time.seconds = i * interval;
		if (profileBlob)
			state->cur_sample->depth.mm = lrintf(profileBlob[i] * 1000.0f);
		else
			state->cur_sample->depth.mm = state->cur_dive->dc.maxdepth.mm;

		if (data[18] && data[18][0])
			state->cur_sample->temperature.mkelvin = C_to_mkelvin(tempBlob[i]);
		if (data[19] && data[19][0])
			state->cur_sample->pressure[0].mbar = pressureBlob[i];
		sample_end(state);
	}

	snprintf(get_events, sizeof(get_events) - 1, get_events_template, state->cur_dive->number);
	retval = sqlite3_exec(handle, get_events, &dm4_events, state, &err);
	if (retval != SQLITE_OK) {
		fprintf(stderr, "%s", "Database query dm4_events failed.\n");
		return 1;
	}

	snprintf(get_events, sizeof(get_events) - 1, get_tags_template, state->cur_dive->number);
	retval = sqlite3_exec(handle, get_events, &dm4_tags, state, &err);
	if (retval != SQLITE_OK) {
		fprintf(stderr, "%s", "Database query dm4_tags failed.\n");
		return 1;
	}

	dive_end(state);

	/*
	for (i=0; i<columns;++i) {
		fprintf(stderr, "%s\t", column[i]);
	}
	fprintf(stderr, "\n");
	for (i=0; i<columns;++i) {
		fprintf(stderr, "%s\t", data[i]);
	}
	fprintf(stderr, "\n");
	//exit(0);
	*/
	return SQLITE_OK;
}
开发者ID:dirkhh,项目名称:subsurface,代码行数:101,代码来源:import-suunto.c


示例8: time_string

// pretty print elapsed (or estimated) number of seconds
static void time_string(uint32_t time, int est, char *buf, size_t len)
{
  	int y = time / 31556736;
  	int d = (time % 31556736) / 86400;
	int h = (time % 86400) / 3600;
	int m = (time % 3600) / 60;
	int s = time % 60;

	if (est) {
		if (y > 0) {
			snprintf(buf, len, "%d years", y);
		} else if (d > 9) {
			snprintf(buf, len, "%dd", d);
		} else if (d > 0) {
			snprintf(buf, len, "%dd%02dh", d, h);
		} else if (h > 9) {
			snprintf(buf, len, "%dh", h);
		} else if (h > 0) {
			snprintf(buf, len, "%dh%02dm", h, m);
		} else if (m > 9) {
			snprintf(buf, len, "%dm", m);
		} else if (m > 0) {
			snprintf(buf, len, "%dm%02ds", m, s);
		} else {
			snprintf(buf, len, "%ds", s);
		}
	} else {
		if (d > 0) {
			snprintf(buf, len, "%dd%d:%02d:%02d", d, h, m, s);
		} else if (h > 0) {
			snprintf(buf, len, "%d:%02d:%02d", h, m, s);
		} else {
			snprintf(buf, len, "%d:%02d", m, s);
		}
	}
}
开发者ID:baiyunping333,项目名称:zmap,代码行数:37,代码来源:monitor.c


示例9: r_anal_value_to_string

// TODO: use esil here?
R_API char *r_anal_op_to_string(RAnal *anal, RAnalOp *op) {
	RAnalFunction *f;
	char ret[128];
	char *cstr;
	char *r0 = r_anal_value_to_string (op->dst);
	char *a0 = r_anal_value_to_string (op->src[0]);
	char *a1 = r_anal_value_to_string (op->src[1]);

	switch (op->type) {
	case R_ANAL_OP_TYPE_MOV:
		snprintf (ret, sizeof (ret), "%s = %s", r0, a0);
		break;
	case R_ANAL_OP_TYPE_CJMP:
		{
		RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
		if (bb) {
			cstr = r_anal_cond_to_string (bb->cond);
			snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, cstr, op->jump);
			free (cstr);
		} else snprintf (ret, sizeof (ret), "if (%s) goto 0x%"PFMT64x, "unk", op->jump);
		}
		break;
	case R_ANAL_OP_TYPE_JMP:
		snprintf (ret, sizeof (ret), "goto 0x%"PFMT64x, op->jump);
		break;
	case R_ANAL_OP_TYPE_UJMP:
		snprintf (ret, sizeof (ret), "goto %s", r0);
		break;
	case R_ANAL_OP_TYPE_PUSH:
	case R_ANAL_OP_TYPE_UPUSH:
		snprintf (ret, sizeof (ret), "push %s", a0);
		break;
	case R_ANAL_OP_TYPE_POP:
		snprintf (ret, sizeof (ret), "pop %s", r0);
		break;
	case R_ANAL_OP_TYPE_UCALL:
		snprintf (ret, sizeof (ret), "%s()", r0);
		break;
	case R_ANAL_OP_TYPE_CALL:
		f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
		if (f) snprintf (ret, sizeof (ret), "%s()", f->name);
		else  snprintf (ret, sizeof (ret), "0x%"PFMT64x"()", op->jump);
		break;
	case R_ANAL_OP_TYPE_CCALL:
		f = r_anal_get_fcn_in (anal, op->jump, R_ANAL_FCN_TYPE_NULL);
		{
		RAnalBlock *bb = r_anal_bb_from_offset (anal, op->addr);
		if (bb) {
			cstr = r_anal_cond_to_string (bb->cond);
			if (f) snprintf (ret, sizeof (ret), "if (%s) %s()", cstr, f->name);
			else snprintf (ret, sizeof (ret), "if (%s) 0x%"PFMT64x"()", cstr, op->jump);
			free (cstr);
		} else {
			if (f) snprintf (ret, sizeof (ret), "if (unk) %s()", f->name);
			else snprintf (ret, sizeof (ret), "if (unk) 0x%"PFMT64x"()", op->jump);
		}
		}
		break;
	case R_ANAL_OP_TYPE_ADD:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s += %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s + %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_SUB:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s -= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s - %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_MUL:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s *= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s * %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_DIV:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s /= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s / %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_AND:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s &= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s & %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_OR:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s |= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s | %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_XOR:
		if (a1 == NULL || !strcmp (a0, a1))
			snprintf (ret, sizeof (ret), "%s ^= %s", r0, a0);
		else snprintf (ret, sizeof (ret), "%s = %s ^ %s", r0, a0, a1);
		break;
	case R_ANAL_OP_TYPE_LEA:
		snprintf (ret, sizeof (ret), "%s -> %s", r0, a0);
		break;
	case R_ANAL_OP_TYPE_CMP:
		memcpy (ret, ";", 2);
		break;
//.........这里部分代码省略.........
开发者ID:deeso,项目名称:radare2,代码行数:101,代码来源:op.c


示例10: XMLRPC_to_xml_element_worker

xml_element* XMLRPC_to_xml_element_worker(XMLRPC_VALUE current_vector, XMLRPC_VALUE node, 
                                          XMLRPC_REQUEST_TYPE request_type, int depth) {
#define BUF_SIZE 512
   xml_element* root = NULL;
   if (node) {
      char buf[BUF_SIZE];
      XMLRPC_VALUE_TYPE type = XMLRPC_GetValueType(node);
      XMLRPC_VECTOR_TYPE vtype = XMLRPC_GetVectorType(node);
      xml_element* elem_val = xml_elem_new();

      /* special case for when root element is not an array */
      if (depth == 0 && 
          !(type == xmlrpc_vector && 
            vtype == xmlrpc_vector_array && 
            request_type == xmlrpc_request_call) ) {
         int bIsFault = (vtype == xmlrpc_vector_struct && XMLRPC_VectorGetValueWithID(node, ELEM_FAULTCODE));

         xml_element* next_el = XMLRPC_to_xml_element_worker(NULL, node, request_type, depth + 1);
         if (next_el) {
            Q_PushTail(&elem_val->children, next_el);
         }
         elem_val->name = strdup(bIsFault ? ELEM_FAULT : ELEM_PARAMS);
        }
        else {
         switch (type) {
            case xmlrpc_empty: //  treat null value as empty string in xmlrpc.
         case xmlrpc_string:
            elem_val->name = strdup(ELEM_STRING);
            simplestring_addn(&elem_val->text, XMLRPC_GetValueString(node), XMLRPC_GetValueStringLen(node));
            break;
         case xmlrpc_int:
            elem_val->name = strdup(ELEM_INT);
            snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueInt(node));
            simplestring_add(&elem_val->text, buf);
            break;
         case xmlrpc_boolean:
            elem_val->name = strdup(ELEM_BOOLEAN);
            snprintf(buf, BUF_SIZE, "%i", XMLRPC_GetValueBoolean(node));
            simplestring_add(&elem_val->text, buf);
            break;
         case xmlrpc_double:
            elem_val->name = strdup(ELEM_DOUBLE);
            snprintf(buf, BUF_SIZE, "%f", XMLRPC_GetValueDouble(node));
            simplestring_add(&elem_val->text, buf);
            break;
         case xmlrpc_datetime:
            elem_val->name = strdup(ELEM_DATETIME);
            simplestring_add(&elem_val->text, XMLRPC_GetValueDateTime_ISO8601(node));
            break;
         case xmlrpc_base64:
            {
               struct buffer_st buf;
               elem_val->name = strdup(ELEM_BASE64);
               base64_encode(&buf, XMLRPC_GetValueBase64(node), XMLRPC_GetValueStringLen(node));
               simplestring_addn(&elem_val->text, buf.data, buf.offset );
               buffer_delete(&buf);
            }
            break;
         case xmlrpc_vector:
            {
               XMLRPC_VECTOR_TYPE my_type = XMLRPC_GetVectorType(node);
               XMLRPC_VALUE xIter = XMLRPC_VectorRewind(node);
               xml_element* root_vector_elem = elem_val;

               switch (my_type) {
               case xmlrpc_vector_array:
                  {
                      if(depth == 0) {
                         elem_val->name = strdup(ELEM_PARAMS);
                      }
                      else {
                         /* Hi my name is Dave and I like to make things as confusing
                          * as possible, thus I will throw in this 'data' element
                          * where it absolutely does not belong just so that people
                          * cannot code arrays and structs in a similar and straight
                          * forward manner. Have a good day.
                          *
                          * GRRRRRRRRR!
                          */
                         xml_element* data = xml_elem_new();
                         data->name = strdup(ELEM_DATA);
    
                         elem_val->name = strdup(ELEM_ARRAY);
                         Q_PushTail(&elem_val->children, data);
                         root_vector_elem = data;
                      }
                  }
                  break;
               case xmlrpc_vector_mixed:       /* not officially supported */
               case xmlrpc_vector_struct:
                  elem_val->name = strdup(ELEM_STRUCT);
                  break;
               default:
                  break;
               }

               /* recurse through sub-elements */
               while ( xIter ) {
                  xml_element* next_el = XMLRPC_to_xml_element_worker(node, xIter, request_type, depth + 1);
                  if (next_el) {
//.........这里部分代码省略.........
开发者ID:Htbaa,项目名称:xmlrpc.mod,代码行数:101,代码来源:xml_to_xmlrpc.c


示例11: monitor_update

static void monitor_update(iterator_t *it, pthread_mutex_t *recv_ready_mutex)
{
	uint32_t total_sent = iterator_get_sent(it);
	if (last_now > 0.0) {
		double age = now() - zsend.start;
		double delta = now() - last_now;
		double remaining_secs = compute_remaining_time(age, total_sent);
		double percent_complete = 100.*age/(age + remaining_secs);


		// ask pcap for fresh values
		pthread_mutex_lock(recv_ready_mutex);
		recv_update_pcap_stats();
		pthread_mutex_unlock(recv_ready_mutex);

		// format times for display
		char time_left[20];
		if (age < 5) {
			time_left[0] = '\0';
		} else {
			char buf[20];
			time_string((int)remaining_secs, 1, buf, sizeof(buf));
			snprintf(time_left, sizeof(time_left), " (%s left)", buf);
		}
		char time_past[20];
		time_string((int)age, 0, time_past, sizeof(time_past));

		char send_rate[20], send_avg[20],
			 recv_rate[20], recv_avg[20],
			 pcap_drop[20], pcap_drop_avg[20];
		// recv stats
		number_string((zrecv.success_unique - last_rcvd)/delta,
						recv_rate, sizeof(recv_rate));
		number_string((zrecv.success_unique/age), recv_avg, sizeof(recv_avg));
		// dropped stats
		number_string((zrecv.pcap_drop + zrecv.pcap_ifdrop - last_drop)/delta,
						pcap_drop, sizeof(pcap_drop));
		number_string(((zrecv.pcap_drop + zrecv.pcap_ifdrop)/age),
						pcap_drop_avg, sizeof(pcap_drop_avg));

		// Warn if we drop > 5% of our average receive rate
		uint32_t drop_rate = (uint32_t)((zrecv.pcap_drop + zrecv.pcap_ifdrop - last_drop) / delta);
		if (drop_rate > (uint32_t)((zrecv.success_unique - last_rcvd) / delta) / 20) {
			log_warn("monitor", "Dropped %d packets in the last second, (%d total dropped (pcap: %d + iface: %d))",
					 drop_rate, zrecv.pcap_drop + zrecv.pcap_ifdrop, zrecv.pcap_drop, zrecv.pcap_ifdrop);
		}

		// Warn if we fail to send > 1% of our average send rate
		uint32_t fail_rate = (uint32_t)((zsend.sendto_failures - last_failures) / delta); // failures/sec
		if (fail_rate > ((total_sent / age) / 100)) {
			log_warn("monitor", "Failed to send %d packets/sec (%d total failures)",
					 fail_rate, zsend.sendto_failures);
		}
		float hits;
		if (!total_sent) {
			hits = 0;
		} else {
			hits = zrecv.success_unique*100./total_sent;
		}
		if (!zsend.complete) {
			// main display (during sending)
			number_string((total_sent - last_sent)/delta,
							send_rate, sizeof(send_rate));
			number_string((total_sent/age), send_avg, sizeof(send_avg));
			fprintf(stderr,
					"%5s %0.0f%%%s; send: %u %sp/s (%sp/s avg); "
					"recv: %u %sp/s (%sp/s avg); "
					"drops: %sp/s (%sp/s avg); "
					"hits: %0.2f%%\n",
					time_past,
					percent_complete,
					time_left,
					total_sent,
					send_rate,
					send_avg,
					zrecv.success_unique,
					recv_rate,
					recv_avg,
					pcap_drop,
					pcap_drop_avg,
					hits);
		} else {
		  	// alternate display (during cooldown)
			number_string((total_sent/(zsend.finish - zsend.start)), send_avg, sizeof(send_avg));
			fprintf(stderr,
					"%5s %0.0f%%%s; send: %u done (%sp/s avg); "
					"recv: %u %sp/s (%sp/s avg); "
					"drops: %sp/s (%sp/s avg); "
					"hits: %0.2f%%\n",
					time_past,
					percent_complete,
					time_left,
					total_sent,
					send_avg,
					zrecv.success_unique,
					recv_rate,
					recv_avg,
					pcap_drop,
					pcap_drop_avg,
					hits);
//.........这里部分代码省略.........
开发者ID:baiyunping333,项目名称:zmap,代码行数:101,代码来源:monitor.c


示例12: Create_Semaphore

int Create_Semaphore (const char *name, int ival)
{
//    struct Semaphore *pSem = 0, *pSemNew = NULL, sem;
    struct Semaphore *pSem;
    int id = 0;

//Print("ARGS. name: %s, ival: %d\n", name, ival);
    /*
     * Obtiene el primer elemento de la lista y lo
     * recorre hasta el final para ver que ID le asigna
     * al semáforo solicitado (poco eficiente).
     */
    pSem = Get_Front_Of_Semaphore_List(&s_semList);
//    Print("LISTA ARRANCA EN %p\n", pSem);
    while (pSem != 0) {
        KASSERT(pSem != Get_Next_In_Semaphore_List(pSem));
        if (strcmp(pSem->name, name) == 0) {
            pSem->nref++;
#ifdef DEBUG
            Print("Semaforo %s ya existe con id %d.\n", name, pSem->id);
#endif
            Print("Semaforo %s ya existe con id %d.\n", name, pSem->id);
            return pSem->id;
        }
        pSem = Get_Next_In_Semaphore_List(pSem);
        id++;
    }

    /* La cantidad máxima de semáforos está siendo utilizada. */
    if (id >= MAX_SEM)
        return -1;

	pSem = Malloc(sizeof (struct Semaphore));
//    Print("ANTES: ");
//    Dump_All_Semaphore_List();
//    sem.id = id;
    pSem->id = id;

    /* Define nombre del semáforo */
//    snprintf(sem.name, sizeof(sem.name), "%s", name);
    snprintf(pSem->name, NAMESIZE, "%s", name);

    /* Define valor inicial del semáforo */
//    sem.value = ival;
    pSem->value = ival;

    /* Referencia a 1 */
//    sem.nref = 1;
    pSem->nref = 1;

/*
	pSemNew = Malloc(sizeof (struct Semaphore));
	pSemNew = &sem;
*/

    /* Agrega semáforo a la lista */
//    Add_To_Back_Of_Semaphore_List(&s_semList, &sem);
//    Add_To_Back_Of_Semaphore_List(&s_semList, pSemNew);
    Add_To_Back_Of_Semaphore_List(&s_semList, pSem);
/*
    sem = Get_Front_Of_Semaphore_List(&s_semList);
    while (sem != NULL) {
        KASSERT(sem != Get_Next_In_Semaphore_List(sem));
        Print("ESTE ID ya esta: %d\n", sem->id);
        sem = Get_Next_In_Semaphore_List(sem);
    }

*/
    Print("DESPUES: ");
    Dump_All_Semaphore_List();
#ifdef DEBUG
    Print("ID: %d\n", id);
#endif
    return id;
}
开发者ID:rjrpaz,项目名称:os-implementation,代码行数:75,代码来源:sem.c


示例13: START_TEST

END_TEST

START_TEST(importdb_can_parse_exported_database)
{
	int i;
	char buffer[512];
	DATA filleddb;
	FILE *exportfile;

	initdb();
	strcpy(data.interface, "something");
	strcpy(data.nick, "nothing");
	data.totalrx = 1;
	data.totaltx = 2;
	data.currx = 3;
	data.curtx = 4;
	data.totalrxk = 5;
	data.totaltxk = 6;
	data.btime = 7;

	for (i=0; i<30; i++) {
		data.day[i].date = i+1;
		data.day[i].rx = data.day[i].tx = i*100;
		data.day[i].rxk = data.day[i].txk = i;
		data.day[i].used = 1;
	}

	for (i=0; i<10; i++) {
		data.top10[i].date = i+1;
		data.top10[i].rx = data.top10[i].tx = i*100;
		data.top10[i].rxk = data.top10[i].txk = i;
		data.top10[i].used = 1;
	}

	for (i=0; i<12; i++) {
		data.month[i].month = i+1;
		data.month[i].rx = data.month[i].tx = i*100;
		data.month[i].rxk = data.month[i].txk = i;
		data.month[i].used = 1;
	}

	for (i=0; i<24; i++) {
		data.hour[i].date = i+1;
		data.hour[i].rx = data.hour[i].tx = i*100;
	}

	memcpy(&filleddb, &data, sizeof(DATA));
	ck_assert_int_eq(remove_directory(TESTDIR), 1);
	ck_assert_int_eq(clean_testdbdir(), 1);

	fflush(stdout);
	snprintf(buffer, 512, "%s/dbexport", TESTDBDIR);
	exportfile = fopen(buffer, "w");
	dup2(fileno(exportfile), STDOUT_FILENO);
	fclose(exportfile);
	exportdb();
	fflush(stdout);
	memset(&data, '\0', sizeof(DATA));

	ck_assert_int_gt(importdb(buffer), 0);

	ck_assert_str_eq(data.interface, filleddb.interface);
	ck_assert_str_eq(data.nick, filleddb.nick);
	ck_assert_int_eq(data.version, filleddb.version);
	ck_assert_int_eq(data.active, filleddb.active);
	ck_assert_int_eq(data.totalrx, filleddb.totalrx);
	ck_assert_int_eq(data.totaltx, filleddb.totaltx);
	ck_assert_int_eq(data.currx, filleddb.currx);
	ck_assert_int_eq(data.curtx, filleddb.curtx);
	ck_assert_int_eq(data.totalrxk, filleddb.totalrxk);
	ck_assert_int_eq(data.totaltxk, filleddb.totaltxk);
	ck_assert_int_eq(data.btime, filleddb.btime);
	ck_assert_int_eq(data.created, filleddb.created);
	ck_assert_int_eq(data.lastupdated, filleddb.lastupdated);

	for (i=0; i<30; i++) {
		ck_assert_int_eq(data.day[i].date, filleddb.day[i].date);
		ck_assert_int_eq(data.day[i].rx, filleddb.day[i].rx);
		ck_assert_int_eq(data.day[i].tx, filleddb.day[i].tx);
		ck_assert_int_eq(data.day[i].rxk, filleddb.day[i].rxk);
		ck_assert_int_eq(data.day[i].txk, filleddb.day[i].txk);
		ck_assert_int_eq(data.day[i].used, filleddb.day[i].used);
	}

	for (i=0; i<10; i++) {
		ck_assert_int_eq(data.top10[i].date, filleddb.top10[i].date);
		ck_assert_int_eq(data.top10[i].rx, filleddb.top10[i].rx);
		ck_assert_int_eq(data.top10[i].tx, filleddb.top10[i].tx);
		ck_assert_int_eq(data.top10[i].rxk, filleddb.top10[i].rxk);
		ck_assert_int_eq(data.top10[i].txk, filleddb.top10[i].txk);
		ck_assert_int_eq(data.top10[i].used, filleddb.top10[i].used);
	}

	for (i=0; i<12; i++) {
		ck_assert_int_eq(data.month[i].month, filleddb.month[i].month);
		ck_assert_int_eq(data.month[i].rx, filleddb.month[i].rx);
		ck_assert_int_eq(data.month[i].tx, filleddb.month[i].tx);
		ck_assert_int_eq(data.month[i].rxk, filleddb.month[i].rxk);
		ck_assert_int_eq(data.month[i].txk, filleddb.month[i].txk);
		ck_assert_int_eq(data.month[i].used, filleddb.month[i].used);
//.........这里部分代码省略.........
开发者ID:alliadt,项目名称:vnstat,代码行数:101,代码来源:database_tests.c


示例14: rpc_call

int rpc_call(struct rpc_context *context, 
    const struct rpc_target *dest, const struct method_t *method, 
    rpc_callback client_cb, void *data) {

    //TODO: check the protocol in dest->proto and do http
    // request only if dest->proto == HTTP
    int res = 1;
    struct evhttp_connection *evcon = NULL;
    struct evhttp_request *req = NULL;
    char *json_method = NULL;
    struct client_rpc_callback_with_data *ctx = NULL;

    //TODO: can be make http_connection as part of peer_t?
    evcon = evhttp_connection_base_new(
        context->base, NULL, dest->host, dest->port);
    if (!evcon) {
        goto cleanup;
    }
    ctx = (struct client_rpc_callback_with_data *)malloc(
        sizeof(struct client_rpc_callback_with_data));
    if(!ctx) {
        goto cleanup;
    }
    ctx->cb = client_cb;
    ctx->data = data;
    ctx->evcon = evcon;

    req = evhttp_request_new(http_request_done, ctx);
    if (!req) {
        goto cleanup;
    }

    char uri[256]; 
    snprintf(uri, sizeof(uri)-1, "http://%s:%d/rpc", dest->host, dest->port);
    
    json_method  = serialize_method_call(method);
    if(!json_method) {
        goto cleanup;
    }

    struct evbuffer *output_buffer = evhttp_request_get_output_buffer(req);
    evbuffer_add(output_buffer, json_method, strlen(json_method));

    char content_length[20];
    snprintf(content_length, sizeof(content_length)-1, "%d", (int)strlen(json_method));

    struct evkeyvalq *output_headers = evhttp_request_get_output_headers(req);
    evhttp_add_header(output_headers, "Host", dest->host);
    evhttp_add_header(output_headers, "Connection", "close");
    evhttp_add_header(output_headers, "Content-Length", content_length);

    printf("Sending req %p with ctx = %p\n", req, ctx);
    int r = evhttp_make_request(evcon, req, EVHTTP_REQ_POST, uri);
    if(!r) {
        res = 0;
    }

cleanup:
    if(json_method)
        free(json_method);
    if(res && ctx)
        free(ctx);
    if(res && evcon)
        evhttp_connection_free(evcon);
    if(res && req)
        evhttp_request_free(req);

    return res;
}
开发者ID:dyustc,项目名称:searaft,代码行数:69,代码来源:rpc.c


示例15: outvol

static void
outvol(struct cfent **eptlist, int eptnum, int part, int nparts)
{
	FILE	*fp;
	char	*svpt, *path, temp[PATH_MAX];
	int	i;


	if (nparts > 1)
		(void) fprintf(stderr, gettext(" -- part %2d:\n"), part);
	if (part == 1) {
		/* re-write pkgmap, but exclude local pathnames */
		(void) snprintf(temp, sizeof (temp), "%s/pkgmap", pkgloc);
		if ((fp = fopen(temp, "w")) == NULL) {
			progerr(gettext(ERR_TEMP), errno);
			quit(99);
		}
		(void) fprintf(fp, ": %d %ld\n", nparts, limit);
		for (i = 0; eptlist[i]; i++) {
			svpt = eptlist[i]->ainfo.local;
			if (!strchr("sl", eptlist[i]->ftype))
				eptlist[i]->ainfo.local = NULL;
			if (ppkgmap(eptlist[i], fp)) {
				progerr(gettext(ERR_TEMP), errno);
				quit(99);
			}
			eptlist[i]->ainfo.local = svpt;
		}
		(void) fclose(fp);
		(void) fprintf(stderr, "%s\n", temp);
	}

	(void) snprintf(temp, sizeof (temp), "%s/pkginfo", pkgloc);
	if (copyf(svept->ainfo.local, temp, svept->cinfo.modtime))
		quit(1);
	(void) fprintf(stderr, "%s\n", temp);

	for (i = 0; i < eptnum; i++) {
		if (eptlist[i]->volno != part)
			continue;
		if (strchr("dxslcbp", eptlist[i]->ftype))
			continue;
		if (eptlist[i]->ftype == 'i') {
			if (eptlist[i] == svept)
				continue; /* don't copy pkginfo file */
			(void) snprintf(temp, sizeof (temp),
				"%s/install/%s", pkgloc,
				eptlist[i]->path);
			path = temp;
		} else
			path = srcpath(pkgloc, eptlist[i]->path, part, nparts);
		if (sflag) {
			if (slinkf(eptlist[i]->ainfo.local, path))
				quit(1);
		} else if (copyf(eptlist[i]->ainfo.local, path,
				eptlist[i]->cinfo.modtime)) {
			quit(1);
		}

		/*
		 * If the package file attributes can be sync'd up with
		 * the pkgmap, we fix the attributes here.
		 */
		if (*(eptlist[i]->ainfo.owner) != '$' &&
		    *(eptlist[i]->ainfo.group) != '$' && getuid() == 0) {
			/* Clear dangerous bits. */
			eptlist[i]->ainfo.mode=
			    (eptlist[i]->ainfo.mode & S_IAMB);
			/*
			 * Make sure it can be read by the world and written
			 * by root.
			 */
			eptlist[i]->ainfo.mode |= 0644;
			if (!strchr("in", eptlist[i]->ftype)) {
				/* Set the safe attributes. */
				averify(1, &(eptlist[i]->ftype),
				    path, &(eptlist[i]->ainfo));
			}
		}

		(void) fprintf(stderr, "%s\n", path);
	}
}
开发者ID:belenix,项目名称:belenixold,代码行数:83,代码来源:main.c


示例16: netfilter_inject_linux


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ snprintf_P函数代码示例发布时间:2022-05-30
下一篇:
C++ snooze函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap