⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnu_java_nio_charset_iconv_iconvdecoder.c

📁 gcc的组建
💻 C
字号:
/* gnu_java_nio_charset_iconv_IconvDecoder.c --   Copyright (C) 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */#include <config.h>#include <jcl.h>#include <stdio.h>#include <assert.h>#include <errno.h>#if defined(HAVE_ICONV)#include <iconv.h>#endif#include "gnu_java_nio_charset_iconv_IconvDecoder.h"static void createRawData (JNIEnv * env, jobject obj, void *ptr);static void *getData (JNIEnv * env, jobject obj);static jfieldID infid = NULL;static jfieldID outfid = NULL;/* Union used for type punning. */union char_union{  jbyte **jb;  jchar **jc;  char **c;};JNIEXPORT void JNICALLJava_gnu_java_nio_charset_iconv_IconvDecoder_openIconv (JNIEnv * env,							jobject obj,							jstring jname){#if defined(HAVE_ICONV)  iconv_t iconv_object;  jclass cls;  const char *name = JCL_jstring_to_cstring (env, jname);  if (name == NULL)    return;  /* Cache fieldIDs for use in decode function. */  if (infid == NULL || outfid == NULL)    {      cls = (*env)->GetObjectClass (env, obj);      infid = (*env)->GetFieldID (env, cls, "inremaining", "I");      assert (infid != 0);      outfid = (*env)->GetFieldID (env, cls, "outremaining", "I");      assert (outfid != 0);    }  /* to java from "name", native java format depends on endianness */#ifdef WORDS_BIGENDIAN  iconv_object = iconv_open ("UTF-16BE", name);#else  iconv_object = iconv_open ("UTF-16LE", name);#endif  JCL_free_cstring (env, jname, name);  if ((long) iconv_object == -1L)    {      JCL_ThrowException (env, "java/lang/IllegalArgumentException",			  "Charset not available");      return;    }  createRawData (env, obj, (void *) iconv_object);#else  JCL_ThrowException (env, "java/lang/IllegalArgumentException",		      "iconv not available");#endif}JNIEXPORT jint JNICALLJava_gnu_java_nio_charset_iconv_IconvDecoder_decode (JNIEnv * env,						     jobject obj,						     jbyteArray inArr,						     jcharArray outArr,						     jint posIn, jint remIn,						     jint posOut, jint remOut){#if defined(HAVE_ICONV)  iconv_t iconv_object = getData (env, obj);  size_t retval;  union char_union in, out;  jbyte *input, *inputcopy;  jchar *output, *outputcopy;  size_t lenIn = (size_t) remIn;  size_t lenOut = (size_t) remOut * 2;  inputcopy = input = (*env)->GetByteArrayElements (env, inArr, 0);  outputcopy = output = (*env)->GetCharArrayElements (env, outArr, 0);  input += posIn;  output += posOut;  in.jb = &input;  out.jc = &output;  retval = iconv (iconv_object, (ICONV_CONST char **) in.c, &lenIn,		  out.c, &lenOut);  /* XXX: Do we need to relase the input array? It's not modified. */  (*env)->ReleaseByteArrayElements (env, inArr, inputcopy, 0);  (*env)->ReleaseCharArrayElements (env, outArr, outputcopy, 0);  if (retval == (size_t) (-1))    {      if (errno == EILSEQ)	retval = 1;      else	retval = 0;    }  else    retval = 0;  (*env)->SetIntField (env, obj, infid, (jint) lenIn);  (*env)->SetIntField (env, obj, outfid, (jint) (lenOut >> 1));  return (jint) retval;#else  return -1;#endif}JNIEXPORT void JNICALLJava_gnu_java_nio_charset_iconv_IconvDecoder_closeIconv (JNIEnv * env,							 jobject obj){#if defined(HAVE_ICONV)  iconv_t iconv_object;  iconv_object = getData (env, obj);  iconv_close (iconv_object);#endif}static voidcreateRawData (JNIEnv * env, jobject obj, void *ptr){  jclass cls;  jobject data;  jfieldID data_fid;  cls = (*env)->GetObjectClass (env, obj);  data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;");  assert (data_fid != 0);  data = JCL_NewRawDataObject(env, ptr);  (*env)->SetObjectField (env, obj, data_fid, data);}static void *getData (JNIEnv * env, jobject obj){  jclass cls;  jfieldID data_fid;  jobject data;  cls = (*env)->GetObjectClass (env, obj);  data_fid = (*env)->GetFieldID (env, cls, "data", "Lgnu/classpath/Pointer;");  assert (data_fid != 0);  data = (*env)->GetObjectField (env, obj, data_fid);  return JCL_GetRawData(env, data);}

⌨️ 快捷键说明

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