mingw: add the mingw stdio functions back

We would rather use the ucrt for these, but sometimes dependencies on
the mingw stdio functions creep in. 仕方ない.

The cost is only paid if they are used; otherwise the symbols are
garbage-collected at link time.
This commit is contained in:
Andrew Kelley 2024-01-07 23:59:42 -07:00
parent 99922c2708
commit 9df0177f33
31 changed files with 7501 additions and 0 deletions

32
lib/libc/mingw/stdio/mingw_asprintf.c vendored Normal file
View File

@ -0,0 +1,32 @@
#define _GNU_SOURCE
#define __CRT__NO_INLINE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int __mingw_asprintf(char ** __restrict__ ret,
const char * __restrict__ format,
...) {
va_list ap;
int len;
va_start(ap,format);
/* Get Length */
len = __mingw_vsnprintf(NULL,0,format,ap);
if (len < 0) goto _end;
/* +1 for \0 terminator. */
*ret = malloc(len + 1);
/* Check malloc fail*/
if (!*ret) {
len = -1;
goto _end;
}
/* Write String */
__mingw_vsnprintf(*ret,len+1,format,ap);
/* Terminate explicitly */
(*ret)[len] = '\0';
_end:
va_end(ap);
return len;
}

View File

@ -0,0 +1,12 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#include <internal.h>
void __cdecl _lock(int locknum);
void __cdecl _unlock(int locknum);
void __cdecl _lock(__UNUSED_PARAM(int locknum)) { }
void __cdecl _unlock(__UNUSED_PARAM(int locknum)) { }

58
lib/libc/mingw/stdio/mingw_fprintf.c vendored Normal file
View File

@ -0,0 +1,58 @@
/* fprintf.c
*
* $Id: fprintf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "fprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "fprintf" will normally be invoked by calling
* "__mingw_fprintf()" in preference to a direct reference to "fprintf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "fprint()". Users who then
* wish to use this implementation may either call "__mingw_fprintf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "fprintf()" to "__mingw_fprintf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "fprintf()" in user
* code will ALWAYS be redirected to "__mingw_fprintf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "fprintf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_fprintf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __fprintf (FILE *, const APICHAR *, ...) __MINGW_NOTHROW;
int __cdecl __fprintf(FILE *stream, const APICHAR *fmt, ...)
{
register int retval;
va_list argv; va_start( argv, fmt );
_lock_file( stream );
retval = __pformat( PFORMAT_TO_FILE | PFORMAT_NOLIMIT, stream, 0, fmt, argv );
_unlock_file( stream );
va_end( argv );
return retval;
}

9
lib/libc/mingw/stdio/mingw_fprintfw.c vendored Normal file
View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_fprintf.c"

21
lib/libc/mingw/stdio/mingw_fscanf.c vendored Normal file
View File

@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
extern int __mingw_vfscanf (FILE *stream, const char *format, va_list argp);
int __mingw_fscanf (FILE *stream, const char *format, ...);
int
__mingw_fscanf (FILE *stream, const char *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vfscanf (stream, format, argp);
va_end (argp);
return r;
}

21
lib/libc/mingw/stdio/mingw_fwscanf.c vendored Normal file
View File

@ -0,0 +1,21 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
extern int __mingw_vfwscanf (FILE *stream, const wchar_t *format, va_list argp);
int __mingw_fwscanf (FILE *stream, const wchar_t *format, ...);
int
__mingw_fwscanf (FILE *stream, const wchar_t *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vfwscanf (stream, format, argp);
va_end (argp);
return r;
}

102
lib/libc/mingw/stdio/mingw_lock.c vendored Normal file
View File

@ -0,0 +1,102 @@
#define _CRTIMP
#include <stdio.h>
#include <synchapi.h>
#include "internal.h"
/***
* Copy of MS functions _lock_file, _unlock_file which are missing from
* msvcrt.dll and msvcr80.dll. They are needed to atomic/lock stdio
* functions (printf, fprintf, vprintf, vfprintf). We need exactly the same
* lock that MS uses in msvcrt.dll because we can mix mingw-w64 code with
* original MS functions (puts, fputs for example).
***/
_CRTIMP void __cdecl _lock(int locknum);
_CRTIMP void __cdecl _unlock(int locknum);
#define _STREAM_LOCKS 16
#define _IOLOCKED 0x8000
/***
* _lock_file - Lock a FILE
*
*Purpose:
* Assert the lock for a stdio-level file
*
*Entry:
* pf = __piob[] entry (pointer to a FILE or _FILEX)
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
void __cdecl _lock_file( FILE *pf )
{
/*
* The way the FILE (pointed to by pf) is locked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= __acrt_iob_func(0)) && (pf <= __acrt_iob_func(_IOB_ENTRIES-1)) )
{
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
*/
_lock( _STREAM_LOCKS + (int)(pf - __acrt_iob_func(0)) );
/* We set _IOLOCKED to indicate we locked the stream */
pf->_flag |= _IOLOCKED;
}
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
EnterCriticalSection( &(((_FILEX *)pf)->lock) );
}
void *__MINGW_IMP_SYMBOL(_lock_file) = _lock_file;
/***
* _unlock_file - Unlock a FILE
*
*Purpose:
* Release the lock for a stdio-level file
*
*Entry:
* pf = __piob[] entry (pointer to a FILE or _FILEX)
*
*Exit:
*
*Exceptions:
*
*******************************************************************************/
void __cdecl _unlock_file( FILE *pf )
{
/*
* The way the FILE (pointed to by pf) is unlocked depends on whether
* it is part of _iob[] or not
*/
if ( (pf >= __acrt_iob_func(0)) && (pf <= __acrt_iob_func(_IOB_ENTRIES-1)) )
{
/*
* FILE lies in _iob[] so the lock lies in _locktable[].
* We reset _IOLOCKED to indicate we unlock the stream.
*/
pf->_flag &= ~_IOLOCKED;
_unlock( _STREAM_LOCKS + (int)(pf - __acrt_iob_func(0)) );
}
else
/*
* Not part of _iob[]. Therefore, *pf is a _FILEX and the
* lock field of the struct is an initialized critical
* section.
*/
LeaveCriticalSection( &(((_FILEX *)pf)->lock) );
}
void *__MINGW_IMP_SYMBOL(_unlock_file) = _unlock_file;

3312
lib/libc/mingw/stdio/mingw_pformat.c vendored Normal file

File diff suppressed because it is too large Load Diff

99
lib/libc/mingw/stdio/mingw_pformat.h vendored Normal file
View File

@ -0,0 +1,99 @@
#ifndef PFORMAT_H
/*
* pformat.h
*
* $Id: pformat.h,v 1.1 2008/07/28 23:24:20 keithmarshall Exp $
*
* A private header, defining the `pformat' API; it is to be included
* in each compilation unit implementing any of the `printf' family of
* functions, but serves no useful purpose elsewhere.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*/
#define PFORMAT_H
/* The following macros reproduce definitions from _mingw.h,
* so that compilation will not choke, if using any compiler
* other than the MinGW implementation of GCC.
*/
#ifndef __cdecl
# ifdef __GNUC__
# define __cdecl __attribute__((__cdecl__))
# else
# define __cdecl
# endif
#endif
#ifndef __MINGW_GNUC_PREREQ
# if defined __GNUC__ && defined __GNUC_MINOR__
# define __MINGW_GNUC_PREREQ( major, minor )\
(__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
# else
# define __MINGW_GNUC_PREREQ( major, minor )
# endif
#endif
#ifndef __MINGW_NOTHROW
# if __MINGW_GNUC_PREREQ( 3, 3 )
# define __MINGW_NOTHROW __attribute__((__nothrow__))
# else
# define __MINGW_NOTHROW
# endif
#endif
#ifdef __BUILD_WIDEAPI
#define APICHAR wchar_t
#else
#define APICHAR char
#endif
/* The following are the declarations specific to the `pformat' API...
*/
#define PFORMAT_TO_FILE 0x2000
#define PFORMAT_NOLIMIT 0x4000
#if defined(__MINGW32__) || defined(__MINGW64__)
/*
* Map MinGW specific function names, for use in place of the generic
* implementation defined equivalent function names.
*/
#ifdef __BUILD_WIDEAPI
# define __pformat __mingw_wpformat
#define __fputc(X,STR) fputwc((wchar_t) (X), (STR))
# define __printf __mingw_wprintf
# define __fprintf __mingw_fwprintf
# define __sprintf __mingw_swprintf
# define __snprintf __mingw_snwprintf
# define __vprintf __mingw_vwprintf
# define __vfprintf __mingw_vfwprintf
# define __vsprintf __mingw_vswprintf
# define __vsnprintf __mingw_vsnwprintf
#else
# define __pformat __mingw_pformat
#define __fputc(X,STR) fputc((X), (STR))
# define __printf __mingw_printf
# define __fprintf __mingw_fprintf
# define __sprintf __mingw_sprintf
# define __snprintf __mingw_snprintf
# define __vprintf __mingw_vprintf
# define __vfprintf __mingw_vfprintf
# define __vsprintf __mingw_vsprintf
# define __vsnprintf __mingw_vsnprintf
#endif /* __BUILD_WIDEAPI */
#endif
int __cdecl __pformat(int, void *, int, const APICHAR *, va_list) __MINGW_NOTHROW;
#endif /* !defined PFORMAT_H */

9
lib/libc/mingw/stdio/mingw_pformatw.c vendored Normal file
View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_pformat.c"

59
lib/libc/mingw/stdio/mingw_printf.c vendored Normal file
View File

@ -0,0 +1,59 @@
/* printf.c
*
* $Id: printf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "printf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "printf" will normally be invoked by calling
* "__mingw_printf()" in preference to a direct reference to "printf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "print()". Users who then
* wish to use this implementation may either call "__mingw_printf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "printf()" to "__mingw_printf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "printf()" in user
* code will ALWAYS be redirected to "__mingw_printf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "printf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_printf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __printf(const APICHAR *, ...) __MINGW_NOTHROW;
int __cdecl __printf(const APICHAR *fmt, ...)
{
register int retval;
va_list argv; va_start( argv, fmt );
_lock_file( stdout );
retval = __pformat( PFORMAT_TO_FILE | PFORMAT_NOLIMIT, stdout, 0, fmt, argv );
_unlock_file( stdout );
va_end( argv );
return retval;
}

9
lib/libc/mingw/stdio/mingw_printfw.c vendored Normal file
View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_printf.c"

28
lib/libc/mingw/stdio/mingw_scanf.c vendored Normal file
View File

@ -0,0 +1,28 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
extern int __mingw_vfscanf (FILE *stream, const char *format, va_list argp);
int __mingw_scanf (const char *format, ...);
int __mingw_vscanf (const char *format, va_list argp);
int
__mingw_scanf (const char *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vfscanf (stdin, format, argp);
va_end (argp);
return r;
}
int
__mingw_vscanf (const char *format, va_list argp)
{
return __mingw_vfscanf (stdin, format, argp);
}

40
lib/libc/mingw/stdio/mingw_snprintf.c vendored Normal file
View File

@ -0,0 +1,40 @@
/* snprintf.c
*
* $Id: snprintf.c,v 1.3 2008/07/28 23:24:20 keithmarshall Exp $
*
* Provides an implementation of the "snprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, replacing the redirection through
* libmoldnames.a, to the MSVCRT standard "_snprintf" function; (the
* standard MSVCRT function remains available, and may be invoked
* directly, using this fully qualified form of its name).
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __snprintf (APICHAR *, size_t, const APICHAR *fmt, ...) __MINGW_NOTHROW;
int __cdecl __vsnprintf (APICHAR *, size_t, const APICHAR *fmt, va_list) __MINGW_NOTHROW;
int __cdecl __snprintf(APICHAR *buf, size_t length, const APICHAR *fmt, ...)
{
va_list argv; va_start( argv, fmt );
register int retval = __vsnprintf( buf, length, fmt, argv );
va_end( argv );
return retval;
}

View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_snprintf.c"

56
lib/libc/mingw/stdio/mingw_sprintf.c vendored Normal file
View File

@ -0,0 +1,56 @@
/* sprintf.c
*
* $Id: sprintf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "sprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "sprintf" will normally be invoked by calling
* "__mingw_sprintf()" in preference to a direct reference to "sprintf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "sprint()". Users who then
* wish to use this implementation may either call "__mingw_sprintf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "sprintf()" to "__mingw_sprintf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "sprintf()" in user
* code will ALWAYS be redirected to "__mingw_sprintf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "sprintf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_sprintf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __sprintf (APICHAR *, const APICHAR *, ...) __MINGW_NOTHROW;
int __cdecl __sprintf(APICHAR *buf, const APICHAR *fmt, ...)
{
register int retval;
va_list argv; va_start( argv, fmt );
buf[retval = __pformat( PFORMAT_NOLIMIT, buf, 0, fmt, argv )] = '\0';
va_end( argv );
return retval;
}

10
lib/libc/mingw/stdio/mingw_sprintfw.c vendored Normal file
View File

@ -0,0 +1,10 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#define _CRT_NON_CONFORMING_SWPRINTFS 1
#include "mingw_sprintf.c"

20
lib/libc/mingw/stdio/mingw_sscanf.c vendored Normal file
View File

@ -0,0 +1,20 @@
#include <stdarg.h>
#include <stdlib.h>
extern int __mingw_vsscanf (const char *buf, const char *format, va_list argp);
int __mingw_sscanf (const char *buf, const char *format, ...);
int
__mingw_sscanf (const char *buf, const char *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vsscanf (buf, format, argp);
va_end (argp);
return r;
}

20
lib/libc/mingw/stdio/mingw_swscanf.c vendored Normal file
View File

@ -0,0 +1,20 @@
#include <stdarg.h>
#include <stdlib.h>
extern int __mingw_vswscanf (const wchar_t *buf, const wchar_t *format, va_list argp);
int __mingw_swscanf (const wchar_t *buf, const wchar_t *format, ...);
int
__mingw_swscanf (const wchar_t *buf, const wchar_t *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vswscanf (buf, format, argp);
va_end (argp);
return r;
}

25
lib/libc/mingw/stdio/mingw_vasprintf.c vendored Normal file
View File

@ -0,0 +1,25 @@
#define _GNU_SOURCE
#define __CRT__NO_INLINE
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
int __mingw_vasprintf(char ** __restrict__ ret,
const char * __restrict__ format,
va_list ap) {
int len;
/* Get Length */
len = __mingw_vsnprintf(NULL,0,format,ap);
if (len < 0) return -1;
/* +1 for \0 terminator. */
*ret = malloc(len + 1);
/* Check malloc fail*/
if (!*ret) return -1;
/* Write String */
__mingw_vsnprintf(*ret,len+1,format,ap);
/* Terminate explicitly */
(*ret)[len] = '\0';
return len;
}

58
lib/libc/mingw/stdio/mingw_vfprintf.c vendored Normal file
View File

@ -0,0 +1,58 @@
/* vfprintf.c
*
* $Id: vfprintf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "vfprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "vfprintf" will normally be invoked by calling
* "__mingw_vfprintf()" in preference to a direct reference to "vfprintf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "vfprint()". Users who then
* wish to use this implementation may either call "__mingw_vfprintf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "vfprintf()" to "__mingw_vfprintf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "vfprintf()" in user
* code will ALWAYS be redirected to "__mingw_vfprintf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "vfprintf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_vfprintf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __vfprintf (FILE *, const APICHAR *, va_list) __MINGW_NOTHROW;
int __cdecl __vfprintf(FILE *stream, const APICHAR *fmt, va_list argv)
{
register int retval;
_lock_file( stream );
retval = __pformat( PFORMAT_TO_FILE | PFORMAT_NOLIMIT, stream, 0, fmt, argv );
_unlock_file( stream );
return retval;
}

View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_vfprintf.c"

1632
lib/libc/mingw/stdio/mingw_vfscanf.c vendored Normal file

File diff suppressed because it is too large Load Diff

58
lib/libc/mingw/stdio/mingw_vprintf.c vendored Normal file
View File

@ -0,0 +1,58 @@
/* vprintf.c
*
* $Id: vprintf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "vprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "vprintf" will normally be invoked by calling
* "__mingw_vprintf()" in preference to a direct reference to "vprintf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "vprint()". Users who then
* wish to use this implementation may either call "__mingw_vprintf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "vprintf()" to "__mingw_vprintf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "vprintf()" in user
* code will ALWAYS be redirected to "__mingw_vprintf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "vprintf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_vprintf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __vprintf (const APICHAR *, va_list) __MINGW_NOTHROW;
int __cdecl __vprintf(const APICHAR *fmt, va_list argv)
{
register int retval;
_lock_file( stdout );
retval = __pformat( PFORMAT_TO_FILE | PFORMAT_NOLIMIT, stdout, 0, fmt, argv );
_unlock_file( stdout );
return retval;
}

9
lib/libc/mingw/stdio/mingw_vprintfw.c vendored Normal file
View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_vprintf.c"

52
lib/libc/mingw/stdio/mingw_vsnprintf.c vendored Normal file
View File

@ -0,0 +1,52 @@
/* vsnprintf.c
*
* $Id: vsnprintf.c,v 1.3 2008/07/28 23:24:20 keithmarshall Exp $
*
* Provides an implementation of the "vsnprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, replacing the redirection through
* libmoldnames.a, to the MSVCRT standard "_vsnprintf" function; (the
* standard MSVCRT function remains available, and may be invoked
* directly, using this fully qualified form of its name).
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __vsnprintf (APICHAR *, size_t, const APICHAR *fmt, va_list) __MINGW_NOTHROW;
int __cdecl __vsnprintf(APICHAR *buf, size_t length, const APICHAR *fmt, va_list argv )
{
register int retval;
if( length == (size_t)(0) )
/*
* No buffer; simply compute and return the size required,
* without actually emitting any data.
*/
return __pformat( 0, buf, 0, fmt, argv);
/* If we get to here, then we have a buffer...
* Emit data up to the limit of buffer length less one,
* then add the requisite NUL terminator.
*/
retval = __pformat( 0, buf, --length, fmt, argv );
buf[retval < (int) length ? retval : (int)length] = '\0';
return retval;
}

View File

@ -0,0 +1,9 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#include "mingw_vsnprintf.c"

54
lib/libc/mingw/stdio/mingw_vsprintf.c vendored Normal file
View File

@ -0,0 +1,54 @@
/* vsprintf.c
*
* $Id: vsprintf.c,v 1.1 2008/08/11 22:41:55 keithmarshall Exp $
*
* Provides an implementation of the "vsprintf" function, conforming
* generally to C99 and SUSv3/POSIX specifications, with extensions
* to support Microsoft's non-standard format specifications. This
* is included in libmingwex.a, whence it may replace the Microsoft
* function of the same name.
*
* Written by Keith Marshall <keithmarshall@users.sourceforge.net>
*
* This implementation of "vsprintf" will normally be invoked by calling
* "__mingw_vsprintf()" in preference to a direct reference to "vsprintf()"
* itself; this leaves the MSVCRT implementation as the default, which
* will be deployed when user code invokes "vsprint()". Users who then
* wish to use this implementation may either call "__mingw_vsprintf()"
* directly, or may use conditional preprocessor defines, to redirect
* references to "vsprintf()" to "__mingw_vsprintf()".
*
* Compiling this module with "-D INSTALL_AS_DEFAULT" will change this
* recommended convention, such that references to "vsprintf()" in user
* code will ALWAYS be redirected to "__mingw_vsprintf()"; if this option
* is adopted, then users wishing to use the MSVCRT implementation of
* "vsprintf()" will be forced to use a "back-door" mechanism to do so.
* Such a "back-door" mechanism is provided with MinGW, allowing the
* MSVCRT implementation to be called as "__msvcrt_vsprintf()"; however,
* since users may not expect this behaviour, a standard libmingwex.a
* installation does not employ this option.
*
*
* This is free software. You may redistribute and/or modify it as you
* see fit, without restriction of copyright.
*
* This software is provided "as is", in the hope that it may be useful,
* but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of
* MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no
* time will the author accept any form of liability for any damages,
* however caused, resulting from the use of this software.
*
*/
#include <stdio.h>
#include <stdarg.h>
#include "mingw_pformat.h"
int __cdecl __vsprintf (APICHAR *, const APICHAR *, va_list) __MINGW_NOTHROW;
int __cdecl __vsprintf(APICHAR *buf, const APICHAR *fmt, va_list argv)
{
register int retval;
buf[retval = __pformat( PFORMAT_NOLIMIT, buf, 0, fmt, argv )] = '\0';
return retval;
}

10
lib/libc/mingw/stdio/mingw_vsprintfw.c vendored Normal file
View File

@ -0,0 +1,10 @@
/**
* This file has no copyright assigned and is placed in the Public Domain.
* This file is part of the mingw-w64 runtime package.
* No warranty is given; refer to the file DISCLAIMER.PD within this package.
*/
#define __BUILD_WIDEAPI 1
#define _CRT_NON_CONFORMING_SWPRINTFS 1
#include "mingw_vsprintf.c"

28
lib/libc/mingw/stdio/mingw_wscanf.c vendored Normal file
View File

@ -0,0 +1,28 @@
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
extern int __mingw_vfwscanf (FILE *stream, const wchar_t *format, va_list argp);
int __mingw_wscanf (const wchar_t *format, ...);
int __mingw_vwscanf (const wchar_t *format, va_list argp);
int
__mingw_wscanf (const wchar_t *format, ...)
{
va_list argp;
int r;
va_start (argp, format);
r = __mingw_vfwscanf (stdin, format, argp);
va_end (argp);
return r;
}
int
__mingw_vwscanf (const wchar_t *format, va_list argp)
{
return __mingw_vfwscanf (stdin, format, argp);
}

1631
lib/libc/mingw/stdio/mingw_wvfscanf.c vendored Normal file

File diff suppressed because it is too large Load Diff