1251875Speter/* Licensed to the Apache Software Foundation (ASF) under one or more 2251875Speter * contributor license agreements. See the NOTICE file distributed with 3251875Speter * this work for additional information regarding copyright ownership. 4251875Speter * The ASF licenses this file to You under the Apache License, Version 2.0 5251875Speter * (the "License"); you may not use this file except in compliance with 6251875Speter * the License. You may obtain a copy of the License at 7251875Speter * 8251875Speter * http://www.apache.org/licenses/LICENSE-2.0 9251875Speter * 10251875Speter * Unless required by applicable law or agreed to in writing, software 11251875Speter * distributed under the License is distributed on an "AS IS" BASIS, 12251875Speter * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13251875Speter * See the License for the specific language governing permissions and 14251875Speter * limitations under the License. 15251875Speter */ 16251875Speter 17251875Speter#include "apr.h" 18251875Speter#include "apr_private.h" 19251875Speter#include "apr_strings.h" 20251875Speter#include "apr_portable.h" 21251875Speter 22251875Speter#ifdef HAVE_LANGINFO_H 23251875Speter#include <langinfo.h> 24251875Speter#endif 25251875Speter 26251875Speter/* 27251875Speter * simple heuristic to determine codepage of source code so that 28251875Speter * literal strings (e.g., "GET /\r\n") in source code can be translated 29251875Speter * properly 30251875Speter * 31251875Speter * If appropriate, a symbol can be set at configure time to determine 32251875Speter * this. On EBCDIC platforms, it will be important how the code was 33251875Speter * unpacked. 34251875Speter */ 35251875Speter 36251875SpeterAPR_DECLARE(const char*) apr_os_default_encoding (apr_pool_t *pool) 37251875Speter{ 38251875Speter#ifdef __MVS__ 39251875Speter# ifdef __CODESET__ 40251875Speter return __CODESET__; 41251875Speter# else 42251875Speter return "IBM-1047"; 43251875Speter# endif 44251875Speter#endif 45251875Speter 46251875Speter if ('}' == 0xD0) { 47251875Speter return "IBM-1047"; 48251875Speter } 49251875Speter 50251875Speter if ('{' == 0xFB) { 51251875Speter return "EDF04"; 52251875Speter } 53251875Speter 54251875Speter if ('A' == 0xC1) { 55251875Speter return "EBCDIC"; /* not useful */ 56251875Speter } 57251875Speter 58251875Speter if ('A' == 0x41) { 59251875Speter return "ISO-8859-1"; /* not necessarily true */ 60251875Speter } 61251875Speter 62251875Speter return "unknown"; 63251875Speter} 64251875Speter 65251875Speter 66251875SpeterAPR_DECLARE(const char*) apr_os_locale_encoding (apr_pool_t *pool) 67251875Speter{ 68251875Speter#if defined(HAVE_NL_LANGINFO) && defined(CODESET) 69251875Speter const char *charset; 70251875Speter 71251875Speter charset = nl_langinfo(CODESET); 72251875Speter if (charset && *charset) { 73251875Speter#ifdef _OSD_POSIX /* Bug workaround - delete as soon as fixed in OSD_POSIX */ 74251875Speter /* Some versions of OSD_POSIX return nl_langinfo(CODESET)="^[nN]" */ 75251875Speter /* Ignore the bogus information and use apr_os_default_encoding() */ 76251875Speter if (charset[0] != '^') 77251875Speter#endif 78251875Speter return apr_pstrdup(pool, charset); 79251875Speter } 80251875Speter#endif 81251875Speter 82251875Speter return apr_os_default_encoding(pool); 83251875Speter} 84