|
Toshihiro Shimizu |
890ddd |
#include <cerrno></cerrno>
|
|
Campbell Barton |
107701 |
#include <cstring> /* memset */</cstring>
|
|
Toshihiro Shimizu |
890ddd |
#include <vector></vector>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdexcept> // std::domain_error(-)</stdexcept>
|
|
Toshihiro Shimizu |
890ddd |
#include <locale></locale>
|
|
Toshihiro Shimizu |
890ddd |
#include <iconv.h></iconv.h>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_resource_msg_from_err.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*------ localeを日本に設定し日本語を扱うことを指示(必須)
|
|
Toshihiro Shimizu |
890ddd |
使う文字コードは"locale -a"で調べる */
|
|
Toshihiro Shimizu |
890ddd |
void igs::resource::locale_to_jp(void)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
setlocale(LC_CTYPE, "ja_JP.utf8");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#if 0 //------
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
リサーチ中
|
|
Toshihiro Shimizu |
890ddd |
日本語環境を環境変数から取ってくる場合のルーチン
|
|
Toshihiro Shimizu |
890ddd |
deamonの場合これでいいのか???
|
|
Toshihiro Shimizu |
890ddd |
さらに調査が必要
|
|
Toshihiro Shimizu |
890ddd |
2013-02-18
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#include <x11 xlib.h=""></x11>
|
|
Toshihiro Shimizu |
890ddd |
#include <x11 xlocale.h=""></x11>
|
|
Toshihiro Shimizu |
890ddd |
void igs::resource::locale_to_jp(void) {
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
Software Design 1993年3月号
|
|
Toshihiro Shimizu |
890ddd |
"SPECIAL ISSUE どうする?UNIXの日本語環境"
|
|
Toshihiro Shimizu |
890ddd |
稚内北星短期大学 丸山 不二夫
|
|
Toshihiro Shimizu |
890ddd |
Page14 リスト4 より
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
X11R5での日本語処理 - ロケールの設定
|
|
Toshihiro Shimizu |
890ddd |
標準的な処理手順
|
|
Toshihiro Shimizu |
890ddd |
全てのX(lib)プログラムの先頭で行う
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 次の場合、環境変数 LANG から、地域名を得ます
|
|
Toshihiro Shimizu |
890ddd |
引数locale が "" の場合、
|
|
Toshihiro Shimizu |
890ddd |
ロケールの各部分の設定には環境変数が参照される。
|
|
Toshihiro Shimizu |
890ddd |
その詳細は実装依存である。
|
|
Toshihiro Shimizu |
890ddd |
Linux Programmer’s Manual July 4, 1999より
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
if ( ::setlocale( LC_ALL ,"" ) == NULL ) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error( "Can not set locale." );
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* Xlibが、現在の地域をサポートしているかチェックします */
|
|
Toshihiro Shimizu |
890ddd |
if ( !::XSupportsLocale() ) {
|
|
Toshihiro Shimizu |
890ddd |
std::string msg("X is not support locale ");
|
|
Toshihiro Shimizu |
890ddd |
msg += setlocale( LC_ALL ,NULL );
|
|
Toshihiro Shimizu |
890ddd |
msg += ".\n";
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error( msg.c_str() );
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* 次の場合、環境変数 XMODIFIERS から修飾子が得られます
|
|
Toshihiro Shimizu |
890ddd |
この修飾子は。入力メソッド (IM) の指定に使われます */
|
|
Toshihiro Shimizu |
890ddd |
if ( ::XSetLocaleModifiers("") == NULL ) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error( "Can not set locale modifiers." );
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
#g++ -L/usr/X11R6/lib/ -lXmu -lXext -lX11 -lgthread -lglib -lm tes82.cxx
|
|
Toshihiro Shimizu |
890ddd |
g++ tes82.cxx -L/usr/X11R6/lib/ -lX11
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
#endif //------
|
|
Toshihiro Shimizu |
890ddd |
/*------ マルチバイト文字列 --> ワイド文字文字列 ------*/
|
|
Toshihiro Shimizu |
890ddd |
void igs::resource::mbs_to_wcs(
|
|
Toshihiro Shimizu |
890ddd |
const std::string &mbs, std::wstring &wcs)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
size_t length = 0;
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const char *src_ptr = mbs.c_str();
|
|
Toshihiro Shimizu |
890ddd |
mbstate_t ss;
|
|
Toshihiro Shimizu |
890ddd |
::memset(&ss, 0, sizeof(ss));
|
|
Toshihiro Shimizu |
890ddd |
length = ::mbsrtowcs(NULL, &src_ptr, 0, &ss);
|
|
Toshihiro Shimizu |
890ddd |
if (length == (size_t)(-1)) { /* 不正なマルチバイト列に遭遇した */
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
"mbstowcs(-) got bad multi byte character,when size");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (length <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
} /* 文字がないなら何もしない */
|
|
Toshihiro Shimizu |
890ddd |
++length;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//std::vector<wchar_t> dst(length);</wchar_t>
|
|
Toshihiro Shimizu |
890ddd |
wcs.resize(length);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const char *src_ptr = mbs.c_str();
|
|
Toshihiro Shimizu |
890ddd |
mbstate_t ss;
|
|
Toshihiro Shimizu |
890ddd |
::memset(&ss, 0, sizeof(ss));
|
|
Toshihiro Shimizu |
890ddd |
//length = ::mbsrtowcs(&dst.at(0) ,&src_ptr ,length ,&ss);
|
|
Toshihiro Shimizu |
890ddd |
length = ::mbsrtowcs(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<wchar_t *="">(wcs.c_str()), &src_ptr, length, &ss);</wchar_t>
|
|
Toshihiro Shimizu |
890ddd |
if (length == (size_t)(-1)) { /* 不正なマルチバイト列に遭遇した */
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
"mbstowcs(-) got bad multi byte character,when conv");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (length <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
"mbstowcs(-) got zero or under equal -2 ");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//wcs = std::wstring(dst.begin() ,dst.end()-1);/* 終端以外を */
|
|
Toshihiro Shimizu |
890ddd |
wcs.erase(wcs.end() - 1); /* 終端文字を消す */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*------ ワイド文字文字列 --> マルチバイト文字列 ------*/
|
|
Toshihiro Shimizu |
890ddd |
void igs::resource::wcs_to_mbs(
|
|
Toshihiro Shimizu |
890ddd |
const std::wstring &wcs, std::string &mbs)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
size_t length = 0;
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const wchar_t *src_ptr = wcs.c_str();
|
|
Toshihiro Shimizu |
890ddd |
mbstate_t ss;
|
|
Toshihiro Shimizu |
890ddd |
::memset(&ss, 0, sizeof(ss));
|
|
Toshihiro Shimizu |
890ddd |
length = ::wcsrtombs(NULL, &src_ptr, 0, &ss);
|
|
Toshihiro Shimizu |
890ddd |
if (length <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
return;
|
|
Toshihiro Shimizu |
890ddd |
} /* 文字がないなら何もしない */
|
|
Toshihiro Shimizu |
890ddd |
++length;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//std::vector<char> dst(length);</char>
|
|
Toshihiro Shimizu |
890ddd |
mbs.resize(length);
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const wchar_t *src_ptr = wcs.c_str();
|
|
Toshihiro Shimizu |
890ddd |
mbstate_t ss;
|
|
Toshihiro Shimizu |
890ddd |
::memset(&ss, 0, sizeof(ss));
|
|
Toshihiro Shimizu |
890ddd |
//length = ::wcsrtombs(&dst.at(0) ,&src_ptr ,length ,&ss);
|
|
Toshihiro Shimizu |
890ddd |
length = ::wcsrtombs(
|
|
Toshihiro Shimizu |
890ddd |
const_cast<char *="">(mbs.c_str()), &src_ptr, length, &ss);</char>
|
|
Toshihiro Shimizu |
890ddd |
if (length <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
"wcstombs(-) got bad wide character");
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
//mbs = std::string(dst.begin() ,dst.end()-1);/* 終端以外を */
|
|
Toshihiro Shimizu |
890ddd |
mbs.erase(mbs.end() - 1); /* 終端文字を消す */
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*------ UNICODE宣言ならマルチバイト文字列をワイド文字文字列に変換 ------*/
|
|
Toshihiro Shimizu |
890ddd |
const std::basic_string<tchar> igs::resource::ts_from_mbs(</tchar>
|
|
Toshihiro Shimizu |
890ddd |
const std::string &mbs)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#if defined UNICODE
|
|
Toshihiro Shimizu |
890ddd |
std::wstring wcs;
|
|
Toshihiro Shimizu |
890ddd |
igs::resource::mbs_to_wcs(mbs, wcs);
|
|
Toshihiro Shimizu |
890ddd |
return wcs;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
/* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */
|
|
Toshihiro Shimizu |
890ddd |
return mbs;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*------ UNICODE宣言ならワイド文字文字列をマルチバイト文字列に変換 ------*/
|
|
Toshihiro Shimizu |
890ddd |
const std::string igs::resource::mbs_from_ts(
|
|
Toshihiro Shimizu |
890ddd |
const std::basic_string<tchar> &ts)</tchar>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
#if defined UNICODE
|
|
Toshihiro Shimizu |
890ddd |
std::string mbs;
|
|
Toshihiro Shimizu |
890ddd |
igs::resource::wcs_to_mbs(ts, mbs);
|
|
Toshihiro Shimizu |
890ddd |
return mbs;
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
/* MBCSの場合のsize()は文字数ではなくchar(byte)数,2bytes文字は2 */
|
|
Toshihiro Shimizu |
890ddd |
return ts;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*------ cp932を含む文字列をutf-8に変換(マルチバイト文字列) ------*/
|
|
Toshihiro Shimizu |
890ddd |
namespace
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
const std::string iconv_to_from_(
|
|
Toshihiro Shimizu |
890ddd |
const std::string &text, const char *tocode, const char *fromcode)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
iconv_t icd = ::iconv_open(tocode, fromcode); // "iconv --list"
|
|
Toshihiro Shimizu |
890ddd |
if (reinterpret_cast<iconv_t>(-1) == icd) {</iconv_t>
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
igs_resource_msg_from_err(TEXT("iconv_open(-)"), errno));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::vector<char> dst(text.size() * 4);</char>
|
|
Toshihiro Shimizu |
890ddd |
char *inbuf = const_cast<char *="">(text.c_str());</char>
|
|
Toshihiro Shimizu |
890ddd |
char *outbuf = &dst.at(0);
|
|
Toshihiro Shimizu |
890ddd |
size_t inbytesleft = text.size();
|
|
Toshihiro Shimizu |
890ddd |
size_t outbytesleft = dst.size();
|
|
Toshihiro Shimizu |
890ddd |
size_t ret = ::iconv(
|
|
Toshihiro Shimizu |
890ddd |
icd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
|
|
Toshihiro Shimizu |
890ddd |
*outbuf = '\0';
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
retに処理した数が入るはずだが、rhel5ではゼロが帰るので、
|
|
Toshihiro Shimizu |
890ddd |
処理数を別途計算する
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
ret = dst.size() - outbytesleft;
|
|
Toshihiro Shimizu |
890ddd |
if (ret <= 0) {
|
|
Toshihiro Shimizu |
890ddd |
//if (static_cast<size_t>(-1) == ret) {</size_t>
|
|
Toshihiro Shimizu |
890ddd |
::iconv_close(icd);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
igs_resource_msg_from_err(TEXT("iconv(-)"), errno));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (-1 == ::iconv_close(icd)) {
|
|
Toshihiro Shimizu |
890ddd |
throw std::domain_error(
|
|
Toshihiro Shimizu |
890ddd |
igs_resource_msg_from_err(TEXT("iconv_close(-)"), errno));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
std::string mbs(std::string(dst.begin(), dst.begin() + ret));
|
|
Toshihiro Shimizu |
890ddd |
return mbs;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const std::string igs::resource::utf8_from_cp932_mb(const std::string &text)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return iconv_to_from_(text, "UTF-8", "CP932"); // "iconv --list"
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
const std::string igs::resource::cp932_from_utf8_mb(const std::string &text)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
return iconv_to_from_(text, "CP932", "UTF-8"); // "iconv --list"
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
/*------ エラーメッセージ表示の元関数、直接呼び出すことはしない ------*/
|
|
Toshihiro Shimizu |
890ddd |
#include <cerrno> // errno</cerrno>
|
|
Toshihiro Shimizu |
890ddd |
#include <cstring> // strerror_r()</cstring>
|
|
Toshihiro Shimizu |
890ddd |
#include <sstream> // std::istringstream</sstream>
|
|
Toshihiro Shimizu |
890ddd |
#include "igs_resource_msg_from_err.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
const std::string igs::resource::msg_from_err_(
|
|
Toshihiro Shimizu |
890ddd |
const std::basic_string<tchar> &tit, const int erno, const std::string &file, const std::string &line, const std::string &pretty_function, const std::string &comp_type, const std::string &gnuc, const std::string &gnuc_minor, const std::string &gnuc_patchlevel, const std::string &gnuc_rh_release, const std::string &date, const std::string &time)</tchar>
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::string errmsg;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/* フルパスで入ってきた場合ファイル名だけにする */
|
|
Toshihiro Shimizu |
890ddd |
std::string::size_type index = file.find_last_of("/\\");
|
|
Toshihiro Shimizu |
890ddd |
if (std::basic_string<tchar>::npos != index) {</tchar>
|
|
Toshihiro Shimizu |
890ddd |
errmsg += file.substr(index + 1);
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
errmsg += file;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += line;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += comp_type;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += gnuc;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '.';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += gnuc_minor;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '.';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += gnuc_patchlevel;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '-';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += gnuc_rh_release;
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
std::istringstream ist(date);
|
|
Toshihiro Shimizu |
890ddd |
std::string month, day, year;
|
|
Toshihiro Shimizu |
890ddd |
ist >> month;
|
|
Toshihiro Shimizu |
890ddd |
ist >> day;
|
|
Toshihiro Shimizu |
890ddd |
ist >> year;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += year;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += month;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += day;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += time;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ' ';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += pretty_function;
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ' ';
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
if (0 < tit.size()) {
|
|
Toshihiro Shimizu |
890ddd |
errmsg += igs::resource::mbs_from_ts(tit);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
if (0 != erno) {
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ':';
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#if defined __HP_aCC
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
HP-UX(v11.23)では、strerror_r()をサポートしない。
|
|
Toshihiro Shimizu |
890ddd |
注意::strerror()はThread SafeではなくMulti Threadでは正常動作しない
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ::strerror(erno);
|
|
Toshihiro Shimizu |
890ddd |
#elif((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && !_GNU_SOURCE)
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3
|
|
Toshihiro Shimizu |
890ddd |
より、POSIX.1.2002で規定されたXSI準拠のバージョンのstrerror_r()
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
char buff[4096];
|
|
Toshihiro Shimizu |
890ddd |
const int ret = ::strerror_r(erno, buff, sizeof(buff));
|
|
Toshihiro Shimizu |
890ddd |
if (0 == ret) {
|
|
Toshihiro Shimizu |
890ddd |
errmsg += buff;
|
|
Toshihiro Shimizu |
890ddd |
} else if (-1 == ret) {
|
|
Toshihiro Shimizu |
890ddd |
swtich(errno)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
case EINVAL:
|
|
Toshihiro Shimizu |
890ddd |
errmsg +=
|
|
Toshihiro Shimizu |
890ddd |
"strerror_r() gets Error : The value of errnum is not a "
|
|
Toshihiro Shimizu |
890ddd |
"valid error number.";
|
|
Toshihiro Shimizu |
890ddd |
/* errnum の値が有効なエラー番号ではない */
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
case ERANGE:
|
|
Toshihiro Shimizu |
890ddd |
errmsg +=
|
|
Toshihiro Shimizu |
890ddd |
"strerror_r() gets Error : Insufficient storage was "
|
|
Toshihiro Shimizu |
890ddd |
"supplied via strerrbuf and buflen to contain the "
|
|
Toshihiro Shimizu |
890ddd |
"generated message string.";
|
|
Toshihiro Shimizu |
890ddd |
/* エラーコードを説明する文字列のために、
|
|
Toshihiro Shimizu |
890ddd |
充分な領域が確保できな かった */
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
deatult:
|
|
Toshihiro Shimizu |
890ddd |
errmsg +=
|
|
Toshihiro Shimizu |
890ddd |
"strerror_r() gets Error and Returns bad errno";
|
|
Toshihiro Shimizu |
890ddd |
break;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
} else {
|
|
Toshihiro Shimizu |
890ddd |
errmsg +=
|
|
Toshihiro Shimizu |
890ddd |
"strerror_r() returns bad value";
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#elif defined(__APPLE__)
|
|
Toshihiro Shimizu |
890ddd |
char buff[4096];
|
|
Toshihiro Shimizu |
890ddd |
int ret = ::strerror_r(erno, buff, sizeof(buff));
|
|
Toshihiro Shimizu |
890ddd |
if (!ret) {
|
|
Toshihiro Shimizu |
890ddd |
errmsg += buff;
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
#else
|
|
Toshihiro Shimizu |
890ddd |
/* linuxはここに来る?
|
|
Toshihiro Shimizu |
890ddd |
http://japanese-linux-man-pages.coding-school.com/man/X_strerror_r-3
|
|
Toshihiro Shimizu |
890ddd |
より、GNU仕様のバージョンのstrerror_r()。非標準の拡張
|
|
Toshihiro Shimizu |
890ddd |
これはThread Safeか??????
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
char buff[4096];
|
|
Toshihiro Shimizu |
890ddd |
const char *ret = ::strerror_r(erno, buff, sizeof(buff));
|
|
Toshihiro Shimizu |
890ddd |
errmsg += ret;
|
|
Toshihiro Shimizu |
890ddd |
#endif
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
errmsg += '\"';
|
|
Toshihiro Shimizu |
890ddd |
return errmsg;
|
|
Toshihiro Shimizu |
890ddd |
}
|