2009-01-28 19:14:13 +01:00
|
|
|
/*
|
|
|
|
* ntdll printf functions
|
|
|
|
*
|
|
|
|
* Copyright 1999, 2009 Alexandre Julliard
|
|
|
|
* Copyright 2000 Jon Griffiths
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winternl.h"
|
|
|
|
#include "ntdll_misc.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
|
|
|
|
|
|
|
|
static const SIZE_T size_max = ~(SIZE_T)0 >> 1;
|
|
|
|
|
|
|
|
typedef struct pf_flags_t
|
|
|
|
{
|
2020-07-07 16:12:44 +02:00
|
|
|
enum { LEN_DEFAULT, LEN_SHORT, LEN_LONG } IntegerLength;
|
|
|
|
BOOLEAN IntegerDouble, IntegerNative, LeftAlign, Alternate, PadZero, WideString;
|
2009-01-28 19:14:13 +01:00
|
|
|
int FieldLength, Precision;
|
2020-07-07 16:12:44 +02:00
|
|
|
char Sign, Format;
|
2009-01-28 19:14:13 +01:00
|
|
|
} pf_flags;
|
|
|
|
|
|
|
|
|
2020-07-07 16:35:04 +02:00
|
|
|
#include "printf.h"
|
|
|
|
#define PRINTF_WIDE
|
|
|
|
#include "printf.h"
|
|
|
|
#undef PRINTF_WIDE
|
2009-01-28 19:14:13 +01:00
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int CDECL _vsnprintf( char *str, size_t len, const char *format, __ms_va_list args )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
2020-07-07 16:35:04 +02:00
|
|
|
pf_output_a out = { str, len };
|
|
|
|
int r = pf_vsnprintf_a( &out, format, args );
|
2009-01-28 19:14:13 +01:00
|
|
|
|
2019-07-03 21:06:14 +02:00
|
|
|
if (out.used < len) str[out.used] = 0;
|
2009-01-28 19:14:13 +01:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _vsnwprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:04:42 +02:00
|
|
|
int CDECL _vsnwprintf( WCHAR *str, size_t len, const WCHAR *format, __ms_va_list args )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
2020-07-07 16:35:04 +02:00
|
|
|
pf_output_w out = { str, len };
|
|
|
|
int r = pf_vsnprintf_w( &out, format, args );
|
2009-01-28 19:14:13 +01:00
|
|
|
|
2019-07-03 21:06:14 +02:00
|
|
|
if (out.used < len) str[out.used] = 0;
|
|
|
|
return r;
|
2009-01-28 19:14:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _snprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:04:42 +02:00
|
|
|
int WINAPIV NTDLL__snprintf( char *str, size_t len, const char *format, ... )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
2020-06-30 12:01:37 +02:00
|
|
|
ret = _vsnprintf( str, len, format, valist );
|
2009-01-28 19:14:13 +01:00
|
|
|
__ms_va_end( valist );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* _snwprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:04:42 +02:00
|
|
|
int WINAPIV _snwprintf( WCHAR *str, size_t len, const WCHAR *format, ... )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start(valist, format);
|
2020-06-30 12:04:42 +02:00
|
|
|
ret = _vsnwprintf( str, len, format, valist );
|
2009-01-28 19:14:13 +01:00
|
|
|
__ms_va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-03 21:06:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _vsnprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int CDECL _vsnprintf_s( char *str, size_t size, size_t len, const char *format, __ms_va_list args )
|
2019-07-03 21:06:21 +02:00
|
|
|
{
|
2020-07-07 16:35:04 +02:00
|
|
|
pf_output_a out = { str, min( size, len ) };
|
|
|
|
int r = pf_vsnprintf_a( &out, format, args );
|
2019-07-03 21:06:21 +02:00
|
|
|
|
|
|
|
if (out.used < size) str[out.used] = 0;
|
|
|
|
else str[0] = 0;
|
|
|
|
if (r == size) r = -1;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 13:33:09 +02:00
|
|
|
/***********************************************************************
|
|
|
|
* _vsnwprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int CDECL _vsnwprintf_s( WCHAR *str, size_t size, size_t len, const WCHAR *format, __ms_va_list args )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
2020-07-07 16:35:04 +02:00
|
|
|
pf_output_w out = { str, min( size, len ) };
|
|
|
|
int r = pf_vsnprintf_w( &out, format, args );
|
2020-05-12 13:33:09 +02:00
|
|
|
|
|
|
|
if (out.used < size) str[out.used] = 0;
|
|
|
|
else str[0] = 0;
|
|
|
|
if (r == size) r = -1;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-07-03 21:06:21 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _snprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int WINAPIV _snprintf_s( char *str, size_t size, size_t len, const char *format, ... )
|
2019-07-03 21:06:21 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
|
|
|
ret = _vsnprintf_s( str, size, len, format, valist );
|
|
|
|
__ms_va_end( valist );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 13:33:09 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* _snwprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int WINAPIV _snwprintf_s( WCHAR *str, size_t size, size_t len, const WCHAR *format, ... )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
|
|
|
ret = _vsnwprintf_s( str, size, len, format, valist );
|
|
|
|
__ms_va_end( valist );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 19:14:13 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* vsprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:04:42 +02:00
|
|
|
int CDECL vsprintf( char *str, const char *format, __ms_va_list args )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
2020-06-30 12:01:37 +02:00
|
|
|
return _vsnprintf( str, size_max, format, args );
|
2009-01-28 19:14:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 13:33:09 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* vsprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int CDECL vsprintf_s( char *str, size_t size, const char *format, __ms_va_list args )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
|
|
|
return _vsnprintf_s( str, size, size, format, args );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* _vswprintf (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:04:42 +02:00
|
|
|
int CDECL _vswprintf( WCHAR *str, const WCHAR *format, __ms_va_list args )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
2020-06-30 12:04:42 +02:00
|
|
|
return _vsnwprintf( str, size_max, format, args );
|
2020-05-12 13:33:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*********************************************************************
|
|
|
|
* vswprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int CDECL vswprintf_s( WCHAR *str, size_t size, const WCHAR *format, __ms_va_list args )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
|
|
|
return _vsnwprintf_s( str, size, size, format, args );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 19:14:13 +01:00
|
|
|
/*********************************************************************
|
|
|
|
* sprintf (NTDLL.@)
|
|
|
|
*/
|
2017-11-02 10:16:54 +01:00
|
|
|
int WINAPIV NTDLL_sprintf( char *str, const char *format, ... )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
2020-06-30 12:01:37 +02:00
|
|
|
ret = _vsnprintf( str, size_max, format, valist );
|
2009-01-28 19:14:13 +01:00
|
|
|
__ms_va_end( valist );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-12 13:33:09 +02:00
|
|
|
/*********************************************************************
|
|
|
|
* sprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int WINAPIV sprintf_s( char *str, size_t size, const char *format, ... )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start( valist, format );
|
|
|
|
ret = vsprintf_s( str, size, format, valist );
|
|
|
|
__ms_va_end( valist );
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-28 19:14:13 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* swprintf (NTDLL.@)
|
|
|
|
*/
|
2017-11-02 10:16:54 +01:00
|
|
|
int WINAPIV NTDLL_swprintf( WCHAR *str, const WCHAR *format, ... )
|
2009-01-28 19:14:13 +01:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start(valist, format);
|
2020-06-30 12:04:42 +02:00
|
|
|
ret = _vsnwprintf( str, size_max, format, valist );
|
2009-01-28 19:14:13 +01:00
|
|
|
__ms_va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|
2020-05-12 13:33:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* swprintf_s (NTDLL.@)
|
|
|
|
*/
|
2020-06-30 12:01:37 +02:00
|
|
|
int WINAPIV swprintf_s( WCHAR *str, size_t size, const WCHAR *format, ... )
|
2020-05-12 13:33:09 +02:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
__ms_va_list valist;
|
|
|
|
|
|
|
|
__ms_va_start(valist, format);
|
|
|
|
ret = vswprintf_s( str, size, format, valist );
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return ret;
|
|
|
|
}
|