PostgreSQL Source Code: src/port/chklocale.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16#ifndef FRONTEND

18#else

20#endif

21

22#ifndef WIN32

23#include <langinfo.h>

24#endif

25

27

28

29

30

31

32

33

34

35

36

37

38

40{

43};

44

51

58

65

70

71

75

80

85

90

95

100

104

108

112

117

121

124

127

140

145

150

155

160

165

170

173

176

179

182

184

186

188};

189

190#ifdef WIN32

191

192

193

194

195

196

197

198

199

200

201static char *

202win32_get_codeset(const char *ctype)

203{

204 char *r = NULL;

205 char *codepage;

207 WCHAR wctype[LOCALE_NAME_MAX_LENGTH];

208

209 memset(wctype, 0, sizeof(wctype));

210 MultiByteToWideChar(CP_ACP, 0, ctype, -1, wctype, LOCALE_NAME_MAX_LENGTH);

211

212 if (GetLocaleInfoEx(wctype,

213 LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,

214 (LPWSTR) &cp, sizeof(cp) / sizeof(WCHAR)) > 0)

215 {

216 r = malloc(16);

217 if (r != NULL)

218 {

219

220

221

222

223 if (cp == CP_ACP)

224 strcpy(r, "utf8");

225 else

227 }

228 }

229 else

230 {

231

232

233

234

235

236

237

238

239

240 codepage = strrchr(ctype, '.');

241 if (codepage != NULL)

242 {

243 size_t ln;

244

245 codepage++;

246 ln = strlen(codepage);

248 if (r != NULL)

249 {

250 if (strspn(codepage, "0123456789") == ln)

251 sprintf(r, "CP%s", codepage);

252 else

253 strcpy(r, codepage);

254 }

255 }

256 }

257

258 return r;

259}

260

261#ifndef FRONTEND

262

263

264

265

266int

267pg_codepage_to_encoding(UINT cp)

268{

269 char sys[16];

270 int i;

271

272 sprintf(sys, "CP%u", cp);

273

274

278

280 (errmsg("could not determine encoding for codeset \"%s\"", sys)));

281

282 return -1;

283}

284#endif

285#endif

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300int

302{

303 char *sys;

304 int i;

305

306#ifndef WIN32

308#endif

309

310

311 if (!ctype)

312 ctype = setlocale(LC_CTYPE, NULL);

313

314

315

319

320

321#ifndef WIN32

322 loc = newlocale(LC_CTYPE_MASK, ctype, (locale_t) 0);

324 return -1;

325

326 sys = nl_langinfo_l(CODESET, loc);

327 if (sys)

328 sys = strdup(sys);

329

330 freelocale(loc);

331#else

332 sys = win32_get_codeset(ctype);

333#endif

334

335 if (!sys)

336 return -1;

337

338

340 {

342 {

345 }

346 }

347

348

349

350#ifdef __darwin__

351

352

353

354

355

356 if (strlen(sys) == 0)

357 {

360 }

361#endif

362

363

364

365

366

367 if (write_message)

368 {

369#ifdef FRONTEND

370 fprintf(stderr, _("could not determine encoding for locale \"%s\": codeset is \"%s\""),

371 ctype, sys);

372

373 fputc('\n', stderr);

374#else

376 (errmsg("could not determine encoding for locale \"%s\": codeset is \"%s\"",

377 ctype, sys)));

378#endif

379 }

380

382 return -1;

383}

static const struct encoding_match encoding_match_list[]

int pg_get_encoding_from_locale(const char *ctype, bool write_message)

#define fprintf(file, fmt, msg)

int errmsg(const char *fmt,...)

#define ereport(elevel,...)

int pg_strcasecmp(const char *s1, const char *s2)

const char * system_enc_name