charset.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Licensed to the Apache Software Foundation (ASF) under one or more
  2. * contributor license agreements. See the NOTICE file distributed with
  3. * this work for additional information regarding copyright ownership.
  4. * The ASF licenses this file to You under the Apache License, Version 2.0
  5. * (the "License"); you may not use this file except in compliance with
  6. * the License. You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "apr.h"
  17. #include "apr_private.h"
  18. #include "apr_strings.h"
  19. #include "apr_portable.h"
  20. #ifdef HAVE_LANGINFO_H
  21. #include <langinfo.h>
  22. #endif
  23. /*
  24. * simple heuristic to determine codepage of source code so that
  25. * literal strings (e.g., "GET /\r\n") in source code can be translated
  26. * properly
  27. *
  28. * If appropriate, a symbol can be set at configure time to determine
  29. * this. On EBCDIC platforms, it will be important how the code was
  30. * unpacked.
  31. */
  32. APR_DECLARE(const char*) apr_os_default_encoding (apr_pool_t *pool)
  33. {
  34. #ifdef __MVS__
  35. # ifdef __CODESET__
  36. return __CODESET__;
  37. # else
  38. return "IBM-1047";
  39. # endif
  40. #endif
  41. if ('}' == 0xD0) {
  42. return "IBM-1047";
  43. }
  44. if ('{' == 0xFB) {
  45. return "EDF04";
  46. }
  47. if ('A' == 0xC1) {
  48. return "EBCDIC"; /* not useful */
  49. }
  50. if ('A' == 0x41) {
  51. return "ISO-8859-1"; /* not necessarily true */
  52. }
  53. return "unknown";
  54. }
  55. APR_DECLARE(const char*) apr_os_locale_encoding (apr_pool_t *pool)
  56. {
  57. #if defined(HAVE_NL_LANGINFO) && defined(CODESET)
  58. const char *charset;
  59. charset = nl_langinfo(CODESET);
  60. if (charset && *charset) {
  61. #ifdef _OSD_POSIX /* Bug workaround - delete as soon as fixed in OSD_POSIX */
  62. /* Some versions of OSD_POSIX return nl_langinfo(CODESET)="^[nN]" */
  63. /* Ignore the bogus information and use apr_os_default_encoding() */
  64. if (charset[0] != '^')
  65. #endif
  66. return charset;
  67. }
  68. #endif
  69. return apr_os_default_encoding(pool);
  70. }