提交 4aaa29bd 编写于 作者: F facetosea

fix:TD-20141 mac os type empty

上级 b9447601
......@@ -97,6 +97,7 @@ LONG WINAPI exceptionHandler(LPEXCEPTION_POINTERS exception);
#include <errno.h>
#include <libproc.h>
#include <sys/sysctl.h>
#else
......@@ -275,34 +276,34 @@ int32_t taosGetEmail(char *email, int32_t maxLen) {
#endif
}
int32_t taosGetOsReleaseName(char *releaseName, int32_t maxLen) {
#ifdef WINDOWS
snprintf(releaseName, maxLen, "Windows");
return 0;
#elif defined(_TD_DARWIN_64)
char line[1024];
size_t size = 0;
int32_t code = -1;
char osversion[32];
size_t osversion_len = sizeof(osversion) - 1;
int osversion_name[] = { CTL_KERN, KERN_OSRELEASE };
TdFilePtr pFile = taosOpenFile("/etc/os-release", TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return false;
if (sysctl(osversion_name, 2, osversion, &osversion_len, NULL, 0) == -1) {
return -1;
}
while ((size = taosGetsFile(pFile, sizeof(line), line)) != -1) {
line[size - 1] = '\0';
if (strncmp(line, "PRETTY_NAME", 11) == 0) {
const char *p = strchr(line, '=') + 1;
if (*p == '"') {
p++;
line[size - 2] = 0;
}
tstrncpy(releaseName, p, maxLen);
code = 0;
break;
}
uint32_t major, minor;
if (sscanf(osversion, "%u.%u", &major, &minor) != 2) {
return -1;
}
if (major >= 20) {
major -= 9; // macOS 11 and newer
sprintf(releaseName, "%u.%u", major, minor);
} else {
major -= 4; // macOS 10.1.1 and newer
sprintf(releaseName, "10.%d.%d", major, minor);
}
taosCloseFile(&pFile);
return code;
return 0;
#else
char line[1024];
size_t size = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册