• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #4720

08 Sep 2025 08:43AM UTC coverage: 58.139% (-0.6%) from 58.762%
#4720

push

travis-ci

web-flow
Merge pull request #32881 from taosdata/enh/add-new-windows-ci

fix(ci): update workflow reference to use new Windows CI YAML

133181 of 292179 branches covered (45.58%)

Branch coverage included in aggregate %.

201691 of 283811 relevant lines covered (71.07%)

5442780.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

79.1
/source/os/src/osLocale.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define ALLOW_FORBID_FUNC
17
#define _DEFAULT_SOURCE
18
#include "osLocale.h"
19
#include "tutil.h"
20

21
#ifdef WINDOWS
22
#if (_WIN64)
23
#include <iphlpapi.h>
24
#include <mswsock.h>
25
#include <psapi.h>
26
#include <stdio.h>
27
#include <windows.h>
28
#include <ws2tcpip.h>
29
#pragma comment(lib, "Mswsock.lib ")
30
#endif
31
#include <objbase.h>
32
#pragma warning(push)
33
#pragma warning(disable : 4091)
34
#include <DbgHelp.h>
35
#pragma warning(pop)
36
#elif defined(_TD_DARWIN_64)
37
#include <errno.h>
38
#include <libproc.h>
39
#else
40
#include <argp.h>
41
#ifndef TD_ASTRA
42
#include <linux/sysctl.h>
43
#include <sys/file.h>
44
#include <sys/resource.h>
45
#include <sys/statvfs.h>
46
#include <sys/syscall.h>
47
#endif
48
#include <sys/utsname.h>
49
#include <unistd.h>
50
#endif
51

52
typedef struct CharsetPair {
53
  char *oldCharset;
54
  char *newCharset;
55
} CharsetPair;
56

57
char *taosCharsetReplace(char *charsetstr) {
6,873✔
58
  if (charsetstr == NULL) {
6,873✔
59
    return NULL;
3✔
60
  }
61
  CharsetPair charsetRep[] = {
6,870✔
62
      {"utf8", "UTF-8"},
63
      {"936", "CP936"},
64
  };
65

66
  for (int32_t i = 0; i < tListLen(charsetRep); ++i) {
20,604✔
67
    if (taosStrcasecmp(charsetRep[i].oldCharset, charsetstr) == 0) {
13,737✔
68
      return taosStrdup(charsetRep[i].newCharset);
3!
69
    }
70
  }
71

72
  return taosStrdup(charsetstr);
6,867!
73
}
74

75
/**
76
 * TODO: here we may employ the systemctl API to set/get the correct locale on the Linux. In some cases, the setlocale
77
 *  seems does not response as expected.
78
 *
79
 * In some Linux systems, setLocale(LC_CTYPE, "") may return NULL, in which case the launch of
80
 * both the Server and the Client may be interrupted.
81
 *
82
 * In case that the setLocale failed to be executed, the right charset needs to be set.
83
 */
84
int32_t taosSetSystemLocale(const char *inLocale) {
6,917✔
85

86
  char *locale = setlocale(LC_CTYPE, inLocale);
6,917✔
87
  if (NULL == locale) {
6,917✔
88
    terrno = TSDB_CODE_INVALID_PARA;
3✔
89
    uError("failed to set locale:%s", inLocale);
3!
90
    return terrno;
3✔
91
  }
92

93
  tstrncpy(tsLocale, locale, TD_LOCALE_LEN);
6,914✔
94
  return 0;
6,914✔
95
}
96

97
void taosGetSystemLocale(char *outLocale, char *outCharset) {
6,870✔
98
  if (outLocale == NULL || outCharset == NULL) return;
6,870✔
99
#ifdef WINDOWS
100
  char *locale = setlocale(LC_CTYPE, "en_US.UTF-8");
101
  if (locale != NULL) {
102
    tstrncpy(outLocale, locale, TD_LOCALE_LEN);
103
  }
104
  tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
105
#else
106
  /*
107
   * POSIX format locale string:
108
   * (Language Strings)_(Country/Region Strings).(code_page)
109
   *
110
   * example: en_US.UTF-8, zh_CN.GB18030, zh_CN.UTF-8,
111
   *
112
   * If user does not specify the locale in taos.cfg, the program then uses default LC_CTYPE as system locale.
113
   *
114
   * In case of some CentOS systems, their default locale is "en_US.utf8", which is not valid code_page
115
   * for libiconv that is employed to convert string in this system. This program will automatically use
116
   * UTF-8 instead as the charset.
117
   *
118
   * In case of windows client, the locale string is not valid POSIX format, user needs to set the
119
   * correct code_page for libiconv. Usually, the code_page of windows system with simple chinese is
120
   * CP936, CP437 for English charset.
121
   *
122
   */
123
  char  sep = '.';
6,864✔
124
  char *locale = NULL;
6,864✔
125

126
  locale = setlocale(LC_CTYPE, "");
6,864✔
127
  if (locale == NULL) {
6,864!
128
    // printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", ERRNO, strerror(ERRNO));
129
    tstrncpy(outLocale, "en_US.UTF-8", TD_LOCALE_LEN);
×
130
  } else {
131
    tstrncpy(outLocale, locale, TD_LOCALE_LEN);
6,864✔
132
    //printf("locale not configured, set to system default:%s\n", outLocale);
133
  }
134

135
  // if user does not specify the charset, extract it from locale
136
  char *str = strrchr(outLocale, sep);
6,864✔
137
  if (str != NULL) {
6,864!
138
    str++;
6,864✔
139

140
    char *revisedCharset = taosCharsetReplace(str);
6,864✔
141
    if (NULL == revisedCharset) {
6,864!
142
      tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
×
143
    } else {
144
      tstrncpy(outCharset, revisedCharset, TD_CHARSET_LEN);
6,864✔
145

146
      taosMemoryFree(revisedCharset);
6,864!
147
    }
148
    // printf("charset not configured, set to system default:%s", outCharset);
149
  } else {
150
    tstrncpy(outCharset, "UTF-8", TD_CHARSET_LEN);
×
151
    // printf("can't get locale and charset from system, set it to UTF-8");
152
  }
153

154
#endif
155
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc