wxcrtbase.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. /*
  2. * Name: wx/wxcrtbase.h
  3. * Purpose: Type-safe ANSI and Unicode builds compatible wrappers for
  4. * CRT functions
  5. * Author: Joel Farley, Ove Kaaven
  6. * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
  7. * Created: 1998/06/12
  8. * Copyright: (c) 1998-2006 wxWidgets dev team
  9. * Licence: wxWindows licence
  10. */
  11. /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
  12. #ifndef _WX_WXCRTBASE_H_
  13. #define _WX_WXCRTBASE_H_
  14. /* -------------------------------------------------------------------------
  15. headers and missing declarations
  16. ------------------------------------------------------------------------- */
  17. #include "wx/chartype.h"
  18. /*
  19. Standard headers we need here.
  20. NB: don't include any wxWidgets headers here because almost all of them
  21. include this one!
  22. NB2: User code should include wx/crt.h instead of including this
  23. header directly.
  24. */
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include <ctype.h>
  28. #include <wctype.h>
  29. #include <time.h>
  30. #if defined(__WINDOWS__) && !defined(__WXWINCE__)
  31. #include <io.h>
  32. #endif
  33. #if defined(HAVE_STRTOK_R) && defined(__DARWIN__) && defined(_MSL_USING_MW_C_HEADERS) && _MSL_USING_MW_C_HEADERS
  34. char *strtok_r(char *, const char *, char **);
  35. #endif
  36. /*
  37. Using -std=c++{98,0x} option with mingw32 disables most of standard
  38. library extensions, so we can't rely on the presence of common non-ANSI
  39. functions, define a special symbol to test for this. Notice that this
  40. doesn't need to be done for g++ under Linux where _GNU_SOURCE (which is
  41. defined by default) still makes all common extensions available even in
  42. ANSI mode.
  43. */
  44. #if defined(__MINGW32__) && defined(__STRICT_ANSI__)
  45. #define __WX_STRICT_ANSI_GCC__
  46. #endif
  47. /*
  48. a few compilers don't have the (non standard but common) isascii function,
  49. define it ourselves for them
  50. */
  51. #ifndef isascii
  52. #if defined(__WX_STRICT_ANSI_GCC__)
  53. #define wxNEED_ISASCII
  54. #elif defined(_WIN32_WCE)
  55. #if _WIN32_WCE <= 211
  56. #define wxNEED_ISASCII
  57. #endif
  58. #endif
  59. #endif /* isascii */
  60. #ifdef wxNEED_ISASCII
  61. inline int isascii(int c) { return (unsigned)c < 0x80; }
  62. #endif
  63. #ifdef _WIN32_WCE
  64. #if _WIN32_WCE <= 211
  65. #define isspace(c) ((c) == wxT(' ') || (c) == wxT('\t'))
  66. #endif
  67. #endif /* _WIN32_WCE */
  68. /* string.h functions */
  69. #ifndef strdup
  70. #if defined(__WXWINCE__)
  71. #if _WIN32_WCE <= 211
  72. #define wxNEED_STRDUP
  73. #endif
  74. #endif
  75. #endif /* strdup */
  76. #ifdef wxNEED_STRDUP
  77. WXDLLIMPEXP_BASE char *strdup(const char* s);
  78. #endif
  79. /* missing functions in some WinCE versions */
  80. #ifdef _WIN32_WCE
  81. #if (_WIN32_WCE < 300)
  82. WXDLLIMPEXP_BASE void *calloc( size_t num, size_t size );
  83. #endif
  84. #endif /* _WIN32_WCE */
  85. /* -------------------------------------------------------------------------
  86. UTF-8 locale handling
  87. ------------------------------------------------------------------------- */
  88. #ifdef __cplusplus
  89. #if wxUSE_UNICODE_UTF8
  90. /* flag indicating whether the current locale uses UTF-8 or not; must be
  91. updated every time the locale is changed! */
  92. #if wxUSE_UTF8_LOCALE_ONLY
  93. #define wxLocaleIsUtf8 true
  94. #else
  95. extern WXDLLIMPEXP_BASE bool wxLocaleIsUtf8;
  96. #endif
  97. /* function used to update the flag: */
  98. extern WXDLLIMPEXP_BASE void wxUpdateLocaleIsUtf8();
  99. #else /* !wxUSE_UNICODE_UTF8 */
  100. inline void wxUpdateLocaleIsUtf8() {}
  101. #endif /* wxUSE_UNICODE_UTF8/!wxUSE_UNICODE_UTF8 */
  102. #endif /* __cplusplus */
  103. /* -------------------------------------------------------------------------
  104. string.h
  105. ------------------------------------------------------------------------- */
  106. #define wxCRT_StrcatA strcat
  107. #define wxCRT_StrchrA strchr
  108. #define wxCRT_StrcmpA strcmp
  109. #define wxCRT_StrcpyA strcpy
  110. #define wxCRT_StrcspnA strcspn
  111. #define wxCRT_StrlenA strlen
  112. #define wxCRT_StrncatA strncat
  113. #define wxCRT_StrncmpA strncmp
  114. #define wxCRT_StrncpyA strncpy
  115. #define wxCRT_StrpbrkA strpbrk
  116. #define wxCRT_StrrchrA strrchr
  117. #define wxCRT_StrspnA strspn
  118. #define wxCRT_StrstrA strstr
  119. #define wxCRT_StrcatW wcscat
  120. #define wxCRT_StrchrW wcschr
  121. #define wxCRT_StrcmpW wcscmp
  122. #define wxCRT_StrcpyW wcscpy
  123. #define wxCRT_StrcspnW wcscspn
  124. #define wxCRT_StrncatW wcsncat
  125. #define wxCRT_StrncmpW wcsncmp
  126. #define wxCRT_StrncpyW wcsncpy
  127. #define wxCRT_StrpbrkW wcspbrk
  128. #define wxCRT_StrrchrW wcsrchr
  129. #define wxCRT_StrspnW wcsspn
  130. #define wxCRT_StrstrW wcsstr
  131. /* these functions are not defined under CE, at least in VC8 CRT */
  132. #if !defined(__WXWINCE__)
  133. #define wxCRT_StrcollA strcoll
  134. #define wxCRT_StrxfrmA strxfrm
  135. #define wxCRT_StrcollW wcscoll
  136. #define wxCRT_StrxfrmW wcsxfrm
  137. #endif /* __WXWINCE__ */
  138. /* Almost all compilers have strdup(), but VC++ and MinGW call it _strdup().
  139. And it's not available in MinGW strict ANSI mode nor under Windows CE. */
  140. #if (defined(__VISUALC__) && __VISUALC__ >= 1400)
  141. #define wxCRT_StrdupA _strdup
  142. #elif defined(__MINGW32__)
  143. #ifndef __WX_STRICT_ANSI_GCC__
  144. #define wxCRT_StrdupA _strdup
  145. #endif
  146. #elif !defined(__WXWINCE__)
  147. #define wxCRT_StrdupA strdup
  148. #endif
  149. /* most Windows compilers provide _wcsdup() */
  150. #if defined(__WINDOWS__) && \
  151. !(defined(__CYGWIN__) || defined(__WX_STRICT_ANSI_GCC__))
  152. #define wxCRT_StrdupW _wcsdup
  153. #elif defined(HAVE_WCSDUP)
  154. #define wxCRT_StrdupW wcsdup
  155. #endif
  156. #ifdef wxHAVE_TCHAR_SUPPORT
  157. /* we surely have wchar_t if we have TCHAR have wcslen() */
  158. #ifndef HAVE_WCSLEN
  159. #define HAVE_WCSLEN
  160. #endif
  161. #endif /* wxHAVE_TCHAR_SUPPORT */
  162. #ifdef HAVE_WCSLEN
  163. #define wxCRT_StrlenW wcslen
  164. #endif
  165. #define wxCRT_StrtodA strtod
  166. #define wxCRT_StrtolA strtol
  167. #define wxCRT_StrtoulA strtoul
  168. #define wxCRT_StrtodW wcstod
  169. #define wxCRT_StrtolW wcstol
  170. #define wxCRT_StrtoulW wcstoul
  171. #ifdef __VISUALC__
  172. #if __VISUALC__ >= 1300 && !defined(__WXWINCE__)
  173. #define wxCRT_StrtollA _strtoi64
  174. #define wxCRT_StrtoullA _strtoui64
  175. #define wxCRT_StrtollW _wcstoi64
  176. #define wxCRT_StrtoullW _wcstoui64
  177. #endif /* VC++ 7+ */
  178. #else
  179. #ifdef HAVE_STRTOULL
  180. #define wxCRT_StrtollA strtoll
  181. #define wxCRT_StrtoullA strtoull
  182. #endif /* HAVE_STRTOULL */
  183. #ifdef HAVE_WCSTOULL
  184. /* assume that we have wcstoull(), which is also C99, too */
  185. #define wxCRT_StrtollW wcstoll
  186. #define wxCRT_StrtoullW wcstoull
  187. #endif /* HAVE_WCSTOULL */
  188. #endif
  189. /*
  190. Only VC8 and later provide strnlen() and wcsnlen() functions under Windows
  191. and it's also only available starting from Windows CE 6.0 only in CE build.
  192. */
  193. #if wxCHECK_VISUALC_VERSION(8) && (!defined(_WIN32_WCE) || (_WIN32_WCE >= 0x600))
  194. #ifndef HAVE_STRNLEN
  195. #define HAVE_STRNLEN
  196. #endif
  197. #ifndef HAVE_WCSNLEN
  198. #define HAVE_WCSNLEN
  199. #endif
  200. #endif
  201. #ifdef HAVE_STRNLEN
  202. #define wxCRT_StrnlenA strnlen
  203. #endif
  204. #ifdef HAVE_WCSNLEN
  205. #define wxCRT_StrnlenW wcsnlen
  206. #endif
  207. /* define wxCRT_StricmpA/W and wxCRT_StrnicmpA/W for various compilers */
  208. #if defined(__BORLANDC__) || defined(__WATCOMC__) || \
  209. defined(__VISAGECPP__) || \
  210. defined(__EMX__) || defined(__DJGPP__)
  211. #define wxCRT_StricmpA stricmp
  212. #define wxCRT_StrnicmpA strnicmp
  213. #elif defined(__SYMANTEC__) || (defined(__VISUALC__) && !defined(__WXWINCE__))
  214. #define wxCRT_StricmpA _stricmp
  215. #define wxCRT_StrnicmpA _strnicmp
  216. #elif defined(__UNIX__) || (defined(__GNUWIN32__) && !defined(__WX_STRICT_ANSI_GCC__))
  217. #define wxCRT_StricmpA strcasecmp
  218. #define wxCRT_StrnicmpA strncasecmp
  219. /* #else -- use wxWidgets implementation */
  220. #endif
  221. #ifdef __VISUALC__
  222. #define wxCRT_StricmpW _wcsicmp
  223. #define wxCRT_StrnicmpW _wcsnicmp
  224. #elif defined(__UNIX__)
  225. #ifdef HAVE_WCSCASECMP
  226. #define wxCRT_StricmpW wcscasecmp
  227. #endif
  228. #ifdef HAVE_WCSNCASECMP
  229. #define wxCRT_StrnicmpW wcsncasecmp
  230. #endif
  231. /* #else -- use wxWidgets implementation */
  232. #endif
  233. #ifdef HAVE_STRTOK_R
  234. #define wxCRT_StrtokA(str, sep, last) strtok_r(str, sep, last)
  235. #endif
  236. /* FIXME-UTF8: detect and use wcstok() if available for wxCRT_StrtokW */
  237. /* these are extern "C" because they are used by regex lib: */
  238. #ifdef __cplusplus
  239. extern "C" {
  240. #endif
  241. #ifndef wxCRT_StrlenW
  242. WXDLLIMPEXP_BASE size_t wxCRT_StrlenW(const wchar_t *s);
  243. #endif
  244. #ifndef wxCRT_StrncmpW
  245. WXDLLIMPEXP_BASE int wxCRT_StrncmpW(const wchar_t *s1, const wchar_t *s2, size_t n);
  246. #endif
  247. #ifdef __cplusplus
  248. }
  249. #endif
  250. /* FIXME-UTF8: remove this once we are Unicode only */
  251. #if wxUSE_UNICODE
  252. #define wxCRT_StrlenNative wxCRT_StrlenW
  253. #define wxCRT_StrncmpNative wxCRT_StrncmpW
  254. #define wxCRT_ToupperNative wxCRT_ToupperW
  255. #define wxCRT_TolowerNative wxCRT_TolowerW
  256. #else
  257. #define wxCRT_StrlenNative wxCRT_StrlenA
  258. #define wxCRT_StrncmpNative wxCRT_StrncmpA
  259. #define wxCRT_ToupperNative toupper
  260. #define wxCRT_TolowerNative tolower
  261. #endif
  262. #ifndef wxCRT_StrcatW
  263. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcatW(wchar_t *dest, const wchar_t *src);
  264. #endif
  265. #ifndef wxCRT_StrchrW
  266. WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrchrW(const wchar_t *s, wchar_t c);
  267. #endif
  268. #ifndef wxCRT_StrcmpW
  269. WXDLLIMPEXP_BASE int wxCRT_StrcmpW(const wchar_t *s1, const wchar_t *s2);
  270. #endif
  271. #ifndef wxCRT_StrcollW
  272. WXDLLIMPEXP_BASE int wxCRT_StrcollW(const wchar_t *s1, const wchar_t *s2);
  273. #endif
  274. #ifndef wxCRT_StrcpyW
  275. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrcpyW(wchar_t *dest, const wchar_t *src);
  276. #endif
  277. #ifndef wxCRT_StrcspnW
  278. WXDLLIMPEXP_BASE size_t wxCRT_StrcspnW(const wchar_t *s, const wchar_t *reject);
  279. #endif
  280. #ifndef wxCRT_StrncatW
  281. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncatW(wchar_t *dest, const wchar_t *src, size_t n);
  282. #endif
  283. #ifndef wxCRT_StrncpyW
  284. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrncpyW(wchar_t *dest, const wchar_t *src, size_t n);
  285. #endif
  286. #ifndef wxCRT_StrpbrkW
  287. WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrpbrkW(const wchar_t *s, const wchar_t *accept);
  288. #endif
  289. #ifndef wxCRT_StrrchrW
  290. WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrrchrW(const wchar_t *s, wchar_t c);
  291. #endif
  292. #ifndef wxCRT_StrspnW
  293. WXDLLIMPEXP_BASE size_t wxCRT_StrspnW(const wchar_t *s, const wchar_t *accept);
  294. #endif
  295. #ifndef wxCRT_StrstrW
  296. WXDLLIMPEXP_BASE const wchar_t *wxCRT_StrstrW(const wchar_t *haystack, const wchar_t *needle);
  297. #endif
  298. #ifndef wxCRT_StrtodW
  299. WXDLLIMPEXP_BASE double wxCRT_StrtodW(const wchar_t *nptr, wchar_t **endptr);
  300. #endif
  301. #ifndef wxCRT_StrtolW
  302. WXDLLIMPEXP_BASE long int wxCRT_StrtolW(const wchar_t *nptr, wchar_t **endptr, int base);
  303. #endif
  304. #ifndef wxCRT_StrtoulW
  305. WXDLLIMPEXP_BASE unsigned long int wxCRT_StrtoulW(const wchar_t *nptr, wchar_t **endptr, int base);
  306. #endif
  307. #ifndef wxCRT_StrxfrmW
  308. WXDLLIMPEXP_BASE size_t wxCRT_StrxfrmW(wchar_t *dest, const wchar_t *src, size_t n);
  309. #endif
  310. #ifndef wxCRT_StrdupA
  311. WXDLLIMPEXP_BASE char *wxCRT_StrdupA(const char *psz);
  312. #endif
  313. #ifndef wxCRT_StrdupW
  314. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrdupW(const wchar_t *pwz);
  315. #endif
  316. #ifndef wxCRT_StricmpA
  317. WXDLLIMPEXP_BASE int wxCRT_StricmpA(const char *psz1, const char *psz2);
  318. #endif
  319. #ifndef wxCRT_StricmpW
  320. WXDLLIMPEXP_BASE int wxCRT_StricmpW(const wchar_t *psz1, const wchar_t *psz2);
  321. #endif
  322. #ifndef wxCRT_StrnicmpA
  323. WXDLLIMPEXP_BASE int wxCRT_StrnicmpA(const char *psz1, const char *psz2, size_t len);
  324. #endif
  325. #ifndef wxCRT_StrnicmpW
  326. WXDLLIMPEXP_BASE int wxCRT_StrnicmpW(const wchar_t *psz1, const wchar_t *psz2, size_t len);
  327. #endif
  328. #ifndef wxCRT_StrtokA
  329. WXDLLIMPEXP_BASE char *wxCRT_StrtokA(char *psz, const char *delim, char **save_ptr);
  330. #endif
  331. #ifndef wxCRT_StrtokW
  332. WXDLLIMPEXP_BASE wchar_t *wxCRT_StrtokW(wchar_t *psz, const wchar_t *delim, wchar_t **save_ptr);
  333. #endif
  334. /* supply strtoll and strtoull, if needed */
  335. #ifdef wxLongLong_t
  336. #ifndef wxCRT_StrtollA
  337. WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollA(const char* nptr,
  338. char** endptr,
  339. int base);
  340. WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullA(const char* nptr,
  341. char** endptr,
  342. int base);
  343. #endif
  344. #ifndef wxCRT_StrtollW
  345. WXDLLIMPEXP_BASE wxLongLong_t wxCRT_StrtollW(const wchar_t* nptr,
  346. wchar_t** endptr,
  347. int base);
  348. WXDLLIMPEXP_BASE wxULongLong_t wxCRT_StrtoullW(const wchar_t* nptr,
  349. wchar_t** endptr,
  350. int base);
  351. #endif
  352. #endif /* wxLongLong_t */
  353. /* -------------------------------------------------------------------------
  354. stdio.h
  355. ------------------------------------------------------------------------- */
  356. #if defined(__UNIX__) || defined(__WXMAC__)
  357. #define wxMBFILES 1
  358. #else
  359. #define wxMBFILES 0
  360. #endif
  361. /* these functions are only needed in the form used for filenames (i.e. char*
  362. on Unix, wchar_t* on Windows), so we don't need to use A/W suffix: */
  363. #if wxMBFILES || !wxUSE_UNICODE /* ANSI filenames */
  364. #define wxCRT_Fopen fopen
  365. #define wxCRT_Freopen freopen
  366. #define wxCRT_Remove remove
  367. #define wxCRT_Rename rename
  368. #else /* Unicode filenames */
  369. /* special case: these functions are missing under Win9x with Unicows so we
  370. have to implement them ourselves */
  371. #if wxUSE_UNICODE_MSLU || defined(__WX_STRICT_ANSI_GCC__)
  372. WXDLLIMPEXP_BASE FILE* wxMSLU__wfopen(const wchar_t *name, const wchar_t *mode);
  373. WXDLLIMPEXP_BASE FILE* wxMSLU__wfreopen(const wchar_t *name, const wchar_t *mode, FILE *stream);
  374. WXDLLIMPEXP_BASE int wxMSLU__wrename(const wchar_t *oldname, const wchar_t *newname);
  375. WXDLLIMPEXP_BASE int wxMSLU__wremove(const wchar_t *name);
  376. #define wxCRT_Fopen wxMSLU__wfopen
  377. #define wxCRT_Freopen wxMSLU__wfreopen
  378. #define wxCRT_Remove wxMSLU__wremove
  379. #define wxCRT_Rename wxMSLU__wrename
  380. #else
  381. /* WinCE CRT doesn't provide these functions so use our own */
  382. #ifdef __WXWINCE__
  383. WXDLLIMPEXP_BASE int wxCRT_Rename(const wchar_t *src,
  384. const wchar_t *dst);
  385. WXDLLIMPEXP_BASE int wxCRT_Remove(const wchar_t *path);
  386. #else
  387. #define wxCRT_Rename _wrename
  388. #define wxCRT_Remove _wremove
  389. #endif
  390. #define wxCRT_Fopen _wfopen
  391. #define wxCRT_Freopen _wfreopen
  392. #endif
  393. #endif /* wxMBFILES/!wxMBFILES */
  394. #define wxCRT_PutsA puts
  395. #define wxCRT_FputsA fputs
  396. #define wxCRT_FgetsA fgets
  397. #define wxCRT_FputcA fputc
  398. #define wxCRT_FgetcA fgetc
  399. #define wxCRT_UngetcA ungetc
  400. #ifdef wxHAVE_TCHAR_SUPPORT
  401. #define wxCRT_PutsW _putws
  402. #define wxCRT_FputsW fputws
  403. #define wxCRT_FputcW fputwc
  404. #endif
  405. #ifdef HAVE_FPUTWS
  406. #define wxCRT_FputsW fputws
  407. #endif
  408. #ifdef HAVE_PUTWS
  409. #define wxCRT_PutsW putws
  410. #endif
  411. #ifdef HAVE_FPUTWC
  412. #define wxCRT_FputcW fputwc
  413. #endif
  414. #define wxCRT_FgetsW fgetws
  415. #ifndef wxCRT_PutsW
  416. WXDLLIMPEXP_BASE int wxCRT_PutsW(const wchar_t *ws);
  417. #endif
  418. #ifndef wxCRT_FputsW
  419. WXDLLIMPEXP_BASE int wxCRT_FputsW(const wchar_t *ch, FILE *stream);
  420. #endif
  421. #ifndef wxCRT_FputcW
  422. WXDLLIMPEXP_BASE int wxCRT_FputcW(wchar_t wc, FILE *stream);
  423. #endif
  424. /*
  425. NB: tmpnam() is unsafe and thus is not wrapped!
  426. Use other wxWidgets facilities instead:
  427. wxFileName::CreateTempFileName, wxTempFile, or wxTempFileOutputStream
  428. */
  429. #define wxTmpnam(x) wxTmpnam_is_insecure_use_wxTempFile_instead
  430. /* FIXME-CE: provide our own perror() using ::GetLastError() */
  431. #ifndef __WXWINCE__
  432. #define wxCRT_PerrorA perror
  433. #ifdef wxHAVE_TCHAR_SUPPORT
  434. #define wxCRT_PerrorW _wperror
  435. #endif
  436. #endif /* !__WXWINCE__ */
  437. /* -------------------------------------------------------------------------
  438. stdlib.h
  439. ------------------------------------------------------------------------- */
  440. /* there are no env vars at all under CE, so no _tgetenv neither */
  441. #ifdef __WXWINCE__
  442. /* can't define as inline function as this is a C file... */
  443. #define wxCRT_GetenvA(name) (name, NULL)
  444. #define wxCRT_GetenvW(name) (name, NULL)
  445. #else
  446. #define wxCRT_GetenvA getenv
  447. #ifdef _tgetenv
  448. #define wxCRT_GetenvW _wgetenv
  449. #endif
  450. #endif
  451. #ifndef wxCRT_GetenvW
  452. WXDLLIMPEXP_BASE wchar_t * wxCRT_GetenvW(const wchar_t *name);
  453. #endif
  454. #define wxCRT_SystemA system
  455. /* mingw32 doesn't provide _tsystem() or _wsystem(): */
  456. #if defined(_tsystem)
  457. #define wxCRT_SystemW _wsystem
  458. #endif
  459. #define wxCRT_AtofA atof
  460. #define wxCRT_AtoiA atoi
  461. #define wxCRT_AtolA atol
  462. #if defined(wxHAVE_TCHAR_SUPPORT) && !defined(__WX_STRICT_ANSI_GCC__)
  463. #define wxCRT_AtoiW _wtoi
  464. #define wxCRT_AtolW _wtol
  465. /* _wtof doesn't exist */
  466. #else
  467. #ifndef __VMS
  468. #define wxCRT_AtofW(s) wcstod(s, NULL)
  469. #endif
  470. #define wxCRT_AtolW(s) wcstol(s, NULL, 10)
  471. /* wcstoi doesn't exist */
  472. #endif
  473. /* -------------------------------------------------------------------------
  474. time.h
  475. ------------------------------------------------------------------------- */
  476. #define wxCRT_StrftimeA strftime
  477. #ifdef __SGI__
  478. /*
  479. IRIX provides not one but two versions of wcsftime(): XPG4 one which
  480. uses "const char*" for the third parameter and so can't be used and the
  481. correct, XPG5, one. Unfortunately we can't just define _XOPEN_SOURCE
  482. high enough to get XPG5 version as this undefines other symbols which
  483. make other functions we use unavailable (see <standards.h> for gory
  484. details). So just declare the XPG5 version ourselves, we're extremely
  485. unlikely to ever be compiled on a system without it. But if we ever do,
  486. a configure test would need to be added for it (and _MIPS_SYMBOL_PRESENT
  487. should be used to check for its presence during run-time, i.e. it would
  488. probably be simpler to just always use our own wxCRT_StrftimeW() below
  489. if it does ever become a problem).
  490. */
  491. #ifdef __cplusplus
  492. extern "C"
  493. #endif
  494. size_t
  495. _xpg5_wcsftime(wchar_t *, size_t, const wchar_t *, const struct tm * );
  496. #define wxCRT_StrftimeW _xpg5_wcsftime
  497. #else
  498. /*
  499. Assume it's always available under non-Unix systems as this does seem
  500. to be the case for now. And under Unix we trust configure to detect it
  501. (except for SGI special case above).
  502. */
  503. #if defined(HAVE_WCSFTIME) || !defined(__UNIX__)
  504. #define wxCRT_StrftimeW wcsftime
  505. #endif
  506. #endif
  507. #ifndef wxCRT_StrftimeW
  508. WXDLLIMPEXP_BASE size_t wxCRT_StrftimeW(wchar_t *s, size_t max,
  509. const wchar_t *fmt,
  510. const struct tm *tm);
  511. #endif
  512. /* -------------------------------------------------------------------------
  513. ctype.h
  514. ------------------------------------------------------------------------- */
  515. #ifdef __WATCOMC__
  516. #define WXWCHAR_T_CAST(c) (wint_t)(c)
  517. #else
  518. #define WXWCHAR_T_CAST(c) c
  519. #endif
  520. #define wxCRT_IsalnumW(c) iswalnum(WXWCHAR_T_CAST(c))
  521. #define wxCRT_IsalphaW(c) iswalpha(WXWCHAR_T_CAST(c))
  522. #define wxCRT_IscntrlW(c) iswcntrl(WXWCHAR_T_CAST(c))
  523. #define wxCRT_IsdigitW(c) iswdigit(WXWCHAR_T_CAST(c))
  524. #define wxCRT_IsgraphW(c) iswgraph(WXWCHAR_T_CAST(c))
  525. #define wxCRT_IslowerW(c) iswlower(WXWCHAR_T_CAST(c))
  526. #define wxCRT_IsprintW(c) iswprint(WXWCHAR_T_CAST(c))
  527. #define wxCRT_IspunctW(c) iswpunct(WXWCHAR_T_CAST(c))
  528. #define wxCRT_IsspaceW(c) iswspace(WXWCHAR_T_CAST(c))
  529. #define wxCRT_IsupperW(c) iswupper(WXWCHAR_T_CAST(c))
  530. #define wxCRT_IsxdigitW(c) iswxdigit(WXWCHAR_T_CAST(c))
  531. #ifdef __GLIBC__
  532. #if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
  533. /* /usr/include/wctype.h incorrectly declares translations */
  534. /* tables which provokes tons of compile-time warnings -- try */
  535. /* to correct this */
  536. #define wxCRT_TolowerW(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
  537. #define wxCRT_ToupperW(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
  538. #else /* !glibc 2.0 */
  539. #define wxCRT_TolowerW towlower
  540. #define wxCRT_ToupperW towupper
  541. #endif
  542. #else /* !__GLIBC__ */
  543. /* There is a bug in VC6 C RTL: toxxx() functions dosn't do anything
  544. with signed chars < 0, so "fix" it here. */
  545. #define wxCRT_TolowerW(c) towlower((wxUChar)(wxChar)(c))
  546. #define wxCRT_ToupperW(c) towupper((wxUChar)(wxChar)(c))
  547. #endif /* __GLIBC__/!__GLIBC__ */
  548. /* -------------------------------------------------------------------------
  549. wx wrappers for CRT functions in both char* and wchar_t* versions
  550. ------------------------------------------------------------------------- */
  551. #ifdef __cplusplus
  552. /* NB: this belongs to wxcrt.h and not this header, but it makes life easier
  553. * for buffer.h and stringimpl.h (both of which must be included before
  554. * string.h, which is required by wxcrt.h) to have them here: */
  555. /* safe version of strlen() (returns 0 if passed NULL pointer) */
  556. inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }
  557. inline size_t wxStrlen(const wchar_t *s) { return s ? wxCRT_StrlenW(s) : 0; }
  558. #ifndef wxWCHAR_T_IS_WXCHAR16
  559. WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar16 *s );
  560. #endif
  561. #ifndef wxWCHAR_T_IS_WXCHAR32
  562. WXDLLIMPEXP_BASE size_t wxStrlen(const wxChar32 *s );
  563. #endif
  564. #define wxWcslen wxCRT_StrlenW
  565. #define wxStrdupA wxCRT_StrdupA
  566. #define wxStrdupW wxCRT_StrdupW
  567. inline char* wxStrdup(const char *s) { return wxCRT_StrdupA(s); }
  568. inline wchar_t* wxStrdup(const wchar_t *s) { return wxCRT_StrdupW(s); }
  569. #ifndef wxWCHAR_T_IS_WXCHAR16
  570. WXDLLIMPEXP_BASE wxChar16* wxStrdup(const wxChar16* s);
  571. #endif
  572. #ifndef wxWCHAR_T_IS_WXCHAR32
  573. WXDLLIMPEXP_BASE wxChar32* wxStrdup(const wxChar32* s);
  574. #endif
  575. #endif /* __cplusplus */
  576. #endif /* _WX_WXCRTBASE_H_ */