标签:str dup c语言 mosquitto ons strdup set squit username
demo:
----return :返回值------------------
int mosquitto_username_pw_set(struct mosquitto *mosq, const char *username, const char *password)
{
if(!mosq) return MOSQ_ERR_INVAL;
if(mosq->username){
_mosquitto_free(mosq->username);
mosq->username = NULL;
}
if(mosq->password){
_mosquitto_free(mosq->password);
mosq->password = NULL;
}
if(username){
mosq->username = _mosquitto_strdup(username);
if(!mosq->username) return MOSQ_ERR_NOMEM;
if(password){
mosq->password = _mosquitto_strdup(password);
if(!mosq->password){
_mosquitto_free(mosq->username);
mosq->username = NULL;
return MOSQ_ERR_NOMEM;
}
}
}
return MOSQ_ERR_SUCCESS;
}
//----------------------------------------------------------------------------------------------------
void main(void){
int x=1;
x= mosquitto_username_pw_set(mosq, username, password);
printf("----------------------------------------------data= %d\n",x);
printf("username= %s\n",username);
}
标签:str dup c语言 mosquitto ons strdup set squit username
原文地址:http://www.cnblogs.com/dpf-learn/p/6963648.html