codeset.c

来自「飞鸽传书的linux源代码」· C语言 代码 · 共 141 行

C
141
字号
#include <errno.h>#include <glib.h>#include "common.h"#define IPMSG_INTERNAL_CODE "UTF-8"#define IPMSG_PROTO_CODE    "CP932"intconvert_string_internal(const char *string,const gchar **to_string){  int rc=0;  gchar *converted_string;  gsize read_len;  gsize write_len;  GError *error_info=NULL;  if ( (!string) || (!to_string) )    return -EINVAL;  converted_string=g_convert((const gchar *)string,			     -1, /* ヌルターミネート */			     IPMSG_INTERNAL_CODE,			     IPMSG_PROTO_CODE,			     &read_len,			     &write_len,			     &error_info);  rc=-EINVAL;  if (!converted_string) {    if (error_info) {      err_out("%s\n",error_info->message);      rc=error_info->code;      g_error_free(error_info);    }    if (rc>0)      rc=-rc;    return rc;  }  *to_string=converted_string;  return 0;}intconvert_string_ipmsg_proto(const char *string,const gchar **to_string){  int rc=0;  gchar *converted_string;  gsize read_len;  gsize write_len;  GError *error_info=NULL;  if ( (!string) || (!to_string) )    return -EINVAL;  converted_string=g_convert((const gchar *)string,			     -1, /* ヌルターミネート */			     IPMSG_PROTO_CODE,			     IPMSG_INTERNAL_CODE,			     &read_len,			     &write_len,			     &error_info);  rc=-EINVAL;  if (!converted_string) {    if (error_info) {      err_out("%s\n",error_info->message);      rc=error_info->code;      g_error_free(error_info);    }    if (rc>0)      rc=-rc;    return rc;  }  *to_string=converted_string;  return 0;}intconvert_string_ipmsg_locale(const char *string,const gchar **to_string){  int rc=0;  gchar *converted_string;  gsize read_len;  gsize write_len;  GError *error_info=NULL;  if ( (!string) || (!to_string) )    return -EINVAL;  converted_string=g_locale_from_utf8((const gchar *)string,			     -1, /* ヌルターミネート */			     &read_len,			     &write_len,			     &error_info);  if (!converted_string) {    if (error_info) {      err_out("%s\n",error_info->message);      rc=error_info->code;      g_error_free(error_info);    }    if (rc>0)      rc=-rc;    return rc;  }  *to_string=converted_string;  return 0;}intconvert_string_ipmsg_filename(const char *string,const gchar **to_string){  int rc=0;  gchar *converted_string;  gsize read_len;  gsize write_len;  GError *error_info=NULL;  if ( (!string) || (!to_string) )    return -EINVAL;  converted_string=g_filename_from_utf8((const gchar *)string,			     -1, /* ヌルターミネート */			     &read_len,			     &write_len,			     &error_info);  rc=-EINVAL;  if (!converted_string) {    if (error_info) {      err_out("%s\n",error_info->message);      rc=error_info->code;      g_error_free(error_info);    }    if (rc>0)      rc=-rc;    return rc;  }  *to_string=converted_string;  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?