#include <stdio.h>
#include "native.h"
#include "cdefs.h"

/*******************************************************************************
  Native code to get the fixed width sizes of the typedefs in cdefs.h
  (e.g. int_1, int_2, int_4, int_8, real_4, real_8, etc.) and the C
  types (size_t, char, short, int, long, long long, float, and double).
  @author  Neon Ngo
  @version $Id: test_cdefs.c,v 1.5 2011/08/09 12:45:10 ntn Exp $
  @since   NeXtMidas 2.9.0
*******************************************************************************/

JNIEXPORT jstring JNICALL Java_nxm_sys_test_test_1cdefs_sizeofNativeTypes
  (JNIEnv *env, jclass class) {
  const int BUF_LEN = 320;
  char buf[BUF_LEN];
  snprintf(buf, BUF_LEN,
#ifdef _WIN
/* NTN: Windows's snprintf does NOT support %zu for size_t, their doc says to use %lu */
    "{NATIVE=TRUE, SIZE_T=%lu, \
      CHAR=%lu, SHORT=%lu, INT=%lu, LONG=%lu, LONG_LONG=%lu, FLOAT=%lu, DOUBLE=%lu, \
      INT_1=%lu, INT_2=%lu, INT_4=%lu, INT_8=%lu, INT_U1=%lu, INT_U2=%lu, INT_U4=%lu, INT_U8=%lu, \
      BOOL_1=%lu, BOOL_2=%lu, BOOL_4=%lu, REAL_4=%lu, REAL_8=%lu}",
#else
    "{NATIVE=TRUE, SIZE_T=%zu, \
      CHAR=%zu, SHORT=%zu, INT=%zu, LONG=%zu, LONG_LONG=%zu, FLOAT=%zu, DOUBLE=%zu, \
      INT_1=%zu, INT_2=%zu, INT_4=%zu, INT_8=%zu, INT_U1=%zu, INT_U2=%zu, INT_U4=%zu, INT_U8=%zu, \
      BOOL_1=%zu, BOOL_2=%zu, BOOL_4=%zu, REAL_4=%zu, REAL_8=%zu}",
#endif
     sizeof(size_t),sizeof(char),   sizeof(short),  sizeof(int), sizeof(long), sizeof(long long), sizeof(float), sizeof(double),
     sizeof(int_1), sizeof(int_2), sizeof(int_4), sizeof(int_8), sizeof(int_u1), sizeof(int_u2), sizeof(int_u4), sizeof(int_u8),
     sizeof(bool_1), sizeof(bool_2), sizeof(bool_4), sizeof(real_4), sizeof(real_8)
  );
  /* printf("sizeofNativeTypes() buf strlen = %d\n buf = %s\n", strlen(buf), buf); // debug */
  return (*env)->NewStringUTF(env, buf);
} /* end sizeofNativeTypes() */
