コード例 #1
0
ファイル: ipcjava.c プロジェクト: abhigoudar/Coaxial-Copter
JNIEXPORT jstring JNICALL Java_ipc_java_primFmttrs_formatGetString (JNIEnv *env,
							   jclass c, jlong buf)
{
  BUFFER_PTR buffer = (BUFFER_PTR)(size_t)buf;
  int length = formatGetInt(buffer);
#define CBUF_LEN 100
  char charBuffer[CBUF_LEN], *tmp;
  jstring theString;

  tmp = charBuffer;
  if (length == 0) {
    charBuffer[0] = '\0';
    formatGetChar(buffer);
  } else {
    if (length >= CBUF_LEN) {
      /* Need to allocate this array because NewStringUTF needs a 
	 null-terminated string.  Sigh... */
      tmp = (char *)malloc(length+1);
    }
    BCOPY(buffer->buffer+buffer->bstart, tmp, length);
    buffer->bstart += length;
    tmp[length] = '\0';
  }
  theString = (*env)->NewStringUTF(env, tmp);
  if (length >= CBUF_LEN) free(tmp);
  return theString;
}
コード例 #2
0
ファイル: ipcFFI.c プロジェクト: StoneAerospace/ipc
const char * formatGetString (BUFFER_PTR buffer)
{
#define CBUF_LEN 100
  static int bufLen = CBUF_LEN;
  static char *charBuffer = NULL;
  if (charBuffer == NULL) charBuffer = (char *)malloc(bufLen);

  int length = formatGetInt(buffer);

  if (length == 0) {
    charBuffer[0] = '\0';
    formatGetChar(buffer); // The 'Z'
  } else {
    if (length >= bufLen) {
      /* Need to re-allocate this array, with room for a null termination */
      free(charBuffer);
      bufLen = length+1;
      charBuffer = (char *)malloc(bufLen);
    }
    BCOPY(buffer->buffer+buffer->bstart, charBuffer, length);
    buffer->bstart += length;
    charBuffer[length] = '\0';
  }
  return charBuffer;
}
コード例 #3
0
ファイル: ipcjava.c プロジェクト: abhigoudar/Coaxial-Copter
JNIEXPORT jchar JNICALL Java_ipc_java_primFmttrs_formatGetChar (JNIEnv *env, jclass c,
						       jlong buffer)
{
  return (jchar)formatGetChar((BUFFER_PTR)(size_t)buffer);
}