Exemple #1
0
static char*
buf_write_using_wctomb (struct HyPortLibrary *portLibrary, const char *buf,
                         IDATA nbytes)
{
    IDATA newLength = 0;
    char *outBuf = (char*)buf;
    newLength = walkUTF8String ((U_8 *) buf, nbytes);
    if (newLength)
    {
        outBuf = portLibrary->mem_allocate_memory (portLibrary, newLength + 1);
        if (outBuf)
        {
            translateUTF8String (buf, outBuf, nbytes);
            nbytes = newLength;
            outBuf[nbytes] = '\0';
        } else
        {
            outBuf = portLibrary->mem_allocate_memory (portLibrary, nbytes + 1);
            memcpy(outBuf, buf, nbytes);
            outBuf[nbytes] = '\0';
        }
        return outBuf;
    }
    outBuf = portLibrary->mem_allocate_memory (portLibrary, nbytes + 1);
    memcpy(outBuf, buf, nbytes);
    outBuf[nbytes] = '\0';
    return outBuf;
}
Exemple #2
0
static intptr_t
file_write_using_wctomb(struct OMRPortLibrary *portLibrary, intptr_t fd, const char *buf, intptr_t nbytes)
{
	intptr_t result = 0;
	intptr_t newLength = 0;
	char stackBuf[512];
	char *newBuf = stackBuf;

	newLength = walkUTF8String((uint8_t *)buf, nbytes);

	if (0 != newLength) {
		if (newLength > sizeof(stackBuf)) {
			newBuf = portLibrary->mem_allocate_memory(portLibrary, newLength, OMR_GET_CALLSITE(), OMRMEM_CATEGORY_PORT_LIBRARY);
		}
		if (NULL != newBuf) {
			translateUTF8String((uint8_t *)buf, (uint8_t *)newBuf, nbytes);
			buf = newBuf;
			nbytes = newLength;
		}
	}

	result = portLibrary->file_write(portLibrary, fd, (void *)buf, nbytes);

	if (newBuf != stackBuf && newBuf != NULL) {
		portLibrary->mem_free_memory(portLibrary, newBuf);
	}

	return (result == nbytes) ? 0 : result;
}
Exemple #3
0
static IDATA
file_write_using_wctomb (struct HyPortLibrary *portLibrary, IDATA fd,
                         const char *buf, IDATA nbytes)
{
  IDATA result;
  IDATA newLength = 0;
  char stackBuf[512];
  char *newBuf = stackBuf;
  newLength = walkUTF8String ((U_8 *) buf, nbytes);
  if (newLength)
    {
      if (newLength > sizeof (stackBuf))
        {
          newBuf = portLibrary->mem_allocate_memory (portLibrary, newLength);
        }
      if (newBuf)
        {
          translateUTF8String (buf, newBuf, nbytes);
          buf = newBuf;
          nbytes = newLength;
        }
    }
  result = portLibrary->file_write (portLibrary, fd, (void *) buf, nbytes);
  if (newBuf != stackBuf && newBuf != NULL)
    {
      portLibrary->mem_free_memory (portLibrary, newBuf);
    }
  return (result == nbytes) ? 0 : result;
}