#ifdef STANDARD
#include <stdio.h>
#include <string.h>
#else
#include <my_global.h>
#include <my_sys.h>
#endif
#include <mysql.h>
#include <m_ctype.h>
#include <m_string.h>

extern "C" {
	my_bool testnull_init(UDF_INIT *, UDF_ARGS *args, char *message);
	char *testnull(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *res_length, char *is_null, char *error);
}

my_bool testnull_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
  if (args->arg_count != 1 || args->arg_type[0] != STRING_RESULT)
  {
    strcpy(message,"Wrong arguments to testnull(string)");
    return 1;
  }
  return 0;
}

char *testnull(UDF_INIT *initid, UDF_ARGS *args, char *result,
	     unsigned long *res_length, char *is_null, char *error) {
  int i;
  unsigned char *word=(unsigned char *)args->args[0];
  if (!word)					// Null argument
  {
    *is_null=1;
    return 0;
  }

  i = args->lengths[0];

  memmove(result, word, i);
  *res_length = (unsigned long)i;

  result[i/2] = '\0';
  return result;
}

