Esempio n. 1
0
File: wstrops.c Progetto: kraj/glibc
void
_IO_wstr_init_static (_IO_FILE *fp, wchar_t *ptr, _IO_size_t size,
		      wchar_t *pstart)
{
  wchar_t *end;

  if (size == 0)
    end = ptr + __wcslen (ptr);
  else if ((_IO_size_t) ptr + size * sizeof (wchar_t) > (_IO_size_t) ptr)
    end = ptr + size;
  else
    /* Even for misaligned ptr make sure there is integral number of wide
       characters.  */
    end = ptr + (-1 - (_IO_size_t) ptr) / sizeof (wchar_t);
  _IO_wsetb (fp, ptr, end, 0);

  fp->_wide_data->_IO_write_base = ptr;
  fp->_wide_data->_IO_read_base = ptr;
  fp->_wide_data->_IO_read_ptr = ptr;
  if (pstart)
    {
      fp->_wide_data->_IO_write_ptr = pstart;
      fp->_wide_data->_IO_write_end = end;
      fp->_wide_data->_IO_read_end = pstart;
    }
  else
    {
      fp->_wide_data->_IO_write_ptr = ptr;
      fp->_wide_data->_IO_write_end = ptr;
      fp->_wide_data->_IO_read_end = end;
    }
  /* A null _allocate_buffer function flags the strfile as being static. */
  (((_IO_strfile *) fp)->_s._allocate_buffer) = (_IO_alloc_type)0;
}
Esempio n. 2
0
int
fputws_unlocked (const wchar_t *str, _IO_FILE *fp)
{
    _IO_size_t len = __wcslen (str);
    int result = EOF;
    CHECK_FILE (fp, EOF);
    if (_IO_fwide (fp, 1) == 1
            && _IO_sputn (fp, (char *) str, len) == len)
        result = 1;
    return result;
}
Esempio n. 3
0
size_t
__wcslcat(wchar_t* dest, const wchar_t* source, size_t maxLength)
{
	size_t destLength = __wcsnlen(dest, maxLength);
	size_t i;

	if (destLength == maxLength) {
		// the destination is already full
		return destLength + __wcslen(source);
	}

	dest += destLength;
	maxLength -= destLength;

	for (i = 0; i < maxLength - 1 && *source != L'\0'; ++i)
		*dest++ = *source++;

	*dest = '\0';

	return destLength + i + __wcslen(source);
}
Esempio n. 4
0
/* Copy SRC to DEST.  */
wchar_t *
__wcscpy (wchar_t *dest, const wchar_t *src)
{
#ifndef UNROLL_NTIMES
  return __wmemcpy (dest, src, __wcslen (src) + 1);
#else
  /* Some architectures might have costly tail function call (powerpc
     for instance) where wmemcpy call overhead for smalls sizes might
     be more costly than just unrolling the main loop.  */
  wchar_t *wcp = dest;

#define ITERATION(index)		\
  ({					\
     wchar_t c = *src++;		\
     *wcp++ = c;			\
     c != L'\0';			\
  })

  while (1)
    UNROLL_REPEAT(UNROLL_NTIMES, ITERATION);
  return dest;
#endif
}