win-pvdrivers

changeset 355:47f67a52a66f

implement RtlStringCbPrintfW.
author Andy Grover <andy.grover@oracle.com>
date Wed Jul 02 11:34:11 2008 -0700 (2008-07-02)
parents 961762808bab
children 429f282ecbb3
files xenpci/mingw_extras.c
line diff
     1.1 --- a/xenpci/mingw_extras.c	Tue Jul 01 15:40:45 2008 -0700
     1.2 +++ b/xenpci/mingw_extras.c	Wed Jul 02 11:34:11 2008 -0700
     1.3 @@ -16,8 +16,35 @@ RtlStringCbPrintfW(
     1.4    win_wchar_t *format,
     1.5    ...)
     1.6  {
     1.7 -  /* TODO: fixme */
     1.8 -  return STATUS_SUCCESS;
     1.9 +  va_list args;
    1.10 +  int len;
    1.11 +  int i;
    1.12 +  char tmp_buf[512];
    1.13 +  NTSTATUS status = STATUS_SUCCESS;
    1.14 +
    1.15 +  if (dest_size > sizeof(tmp_buf))
    1.16 +    dest_size = sizeof(tmp_buf);
    1.17 +
    1.18 +  /* we don't have a 2-byte version of vsnprintf, so write it to a single-byte
    1.19 +     array using vsnprintf() and then copy result to the wchar buffer.
    1.20 +     This should be seldom executed, so this inefficiency should be ok. */
    1.21 +  va_start(args, format);
    1.22 +  len = vsnprintf(tmp_buf, sizeof(tmp_buf), (char *)format, args);
    1.23 +  va_end(args);
    1.24 +
    1.25 +  if (len >= (dest_size * sizeof(win_wchar_t))) {
    1.26 +    /* output buffer truncated */
    1.27 +    status = STATUS_BUFFER_OVERFLOW;
    1.28 +    tmp_buf[sizeof(tmp_buf)-1] = '\0';
    1.29 +  }
    1.30 +
    1.31 +  /* copy byte-string to short_string, incl NULL */
    1.32 +  for (i = 0; i < (len + 1); i++)
    1.33 +  {
    1.34 +    dest_str[i] = tmp_buf[i];
    1.35 +  }
    1.36 +
    1.37 +  return status;
    1.38  }
    1.39  
    1.40  /* ----- BEGIN Other people's code --------- */