static char *TCPCommand; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int SetUpTCPtoSendInformation(char option[], char **command) { static int isFirstCall = 1; pthread_mutex_lock(&mutex); // 加锁 if (isFirstCall && strstr(option, "set")) { CON_LOG("33\n"); if (TCPCommand != NULL) { free(TCPCommand); CON_LOG("33\n"); } CON_LOG("33\n"); TCPCommand = malloc(strlen(*command) + 1); CON_LOG("33\n"); if (TCPCommand == NULL) { printf("Failed to set and obtain TCP command variable memory allocation\n"); goto fail; } CON_LOG("33\n"); strcpy(TCPCommand, *command); CON_LOG("set:%s\n", TCPCommand); isFirstCall = 0; goto succeed; } else if (!isFirstCall && strstr(option, "get") && TCPCommand != NULL && strlen(TCPCommand)) { free(*command); *command = malloc(strlen(TCPCommand) + 1); strcpy(*command, TCPCommand); CON_LOG("get:%s\n", *command); memset(TCPCommand, '\0', strlen(TCPCommand)); free(TCPCommand); TCPCommand = NULL; isFirstCall = 1; goto succeed; }else { *command = malloc(1); if (*command == NULL) { CON_LOG("Failed to allocate memory for command\n"); goto fail; } **command = '\0'; CON_LOG("Invalid option\n"); goto fail; } fail: pthread_mutex_unlock(&mutex); // 解锁 return 0; succeed: pthread_mutex_unlock(&mutex); // 解锁 return 1; } SetUpTCPtoSendInformation("set","echo `uci get m_system.usesiminfo.operator;uci get m_system.usesiminfo.card_slot; \ uci get m_system.usesiminfo.iccid;uci get m_system.usesiminfo.lock;uci get m_system.system.simnum`");调用报错
时间: 2024-04-13 19:29:55 浏览: 85
pthread_cond_wait() 用法深入分析
根据您提供的代码和调用,我注意到在 `SetUpTCPtoSendInformation` 函数的调用中,您提供的参数字符串可能存在问题。在C语言中,字符串常量应该用双引号 `"` 括起来,而不是单引号 `'`。
请尝试将以下代码修改为双引号括起来的字符串常量:
```c
SetUpTCPtoSendInformation("set", "echo `uci get m_system.usesiminfo.operator;uci get m_system.usesiminfo.card_slot; \
uci get m_system.usesiminfo.iccid;uci get m_system.usesiminfo.lock;uci get m_system.system.simnum`");
```
这样修改后,编译器应该能够正确解析字符串参数,并将其传递给函数。
如果问题仍然存在,请提供更详细的错误信息或相关代码,以便我可以更好地帮助您解决问题。
阅读全文