Replace __mingw_snprintf() with new generic family implementation; likewise, replace __mingw_vsnprintf().
This commit is contained in:
		| @@ -1,3 +1,20 @@ | ||||
| 2008-07-29  Keith Marshall  <keithmarshall@users.sourceforge.net> | ||||
|  | ||||
| 	Replace __mingw_snprintf() with new generic family implementation; | ||||
| 	likewise, replace __mingw_vsnprintf(). | ||||
|  | ||||
| 	* mingwex/stdio/pformat.c mingwex/stdio/pformat.h: New files. | ||||
| 	* mingwex/stdio/snprintf.c mingwex/stdio/vsnprintf.c: New files. | ||||
| 	* mingwex/Makefile.in (STDIO_DISTFILES): Add them. | ||||
| 	(GDTOA_DISTFILES): Remove mingw_snprintf.c | ||||
| 	(STDIO_OBJS): Add pformat.o, snprintf.o and vsnprintf.o | ||||
| 	(GDTOA_OBJS): Remove mingw_snprintf.o | ||||
| 	(PFORMAT_CFLAGS): New macro; define it, as required by... | ||||
| 	(pformat.o): ...this new explicit build target. | ||||
| 	(snprintf.o, vsnprintf.o): Declare prerequisites. | ||||
|  | ||||
| 	* mingwex/gdtoa/mingw_snprintf.c: Redundant file; delete it. | ||||
|  | ||||
| 2008-07-28  Keith Marshall  <keithmarshall@users.sourceforge.net> | ||||
|  | ||||
| 	Lay foundations for new printf() function family implementation. | ||||
|   | ||||
| @@ -25,7 +25,9 @@ INSTALL = @INSTALL@ | ||||
| INSTALL_DATA = @INSTALL_DATA@ | ||||
| INSTALL_PROGRAM = @INSTALL_PROGRAM@ | ||||
| mkinstalldirs = $(SHELL) $(srcdir)/../mkinstalldirs | ||||
| DISTFILES = Makefile.in configure configure.in aclocal.m4 \ | ||||
|  | ||||
| DISTFILES = \ | ||||
| 	Makefile.in configure configure.in aclocal.m4 \ | ||||
| 	_Exit.c atoll.c dirent.c feclearexcept.c fegetenv.c \ | ||||
| 	fegetexceptflag.c fegetround.c feholdexcept.c feraiseexcept.c \ | ||||
| 	fesetenv.c fesetexceptflag.c fesetround.c fetestexcept.c \ | ||||
| @@ -37,8 +39,7 @@ DISTFILES = Makefile.in configure configure.in aclocal.m4 \ | ||||
| 	wdirent.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c wtoll.c \ | ||||
| 	wcrtomb.c wctob.c mbrtowc.c btowc.c mb_wc_common.h \ | ||||
| 	gettimeofday.c isblank.c iswblank.c \ | ||||
| 	basename.c dirname.c \ | ||||
| 	usleep.c \ | ||||
| 	basename.c dirname.c usleep.c \ | ||||
| 	tsearch.c twalk.c tdelete.c tfind.c | ||||
|  | ||||
| MATH_DISTFILES = \ | ||||
| @@ -67,12 +68,13 @@ MATH_DISTFILES = \ | ||||
| 	signbit.c signbitf.c signbitl.c sinf.S sinhf.c sinhl.c sinl.S \ | ||||
| 	sqrtf.c sqrtl.c tanf.S tanhf.c tanhl.c tanl.S tgamma.c \ | ||||
| 	tgammaf.c tgammal.c trunc.c truncf.c truncl.c \ | ||||
| 	acosh.c acoshf.c acoshl.c  asinh.c asinhf.c asinhl.c \ | ||||
| 	acosh.c acoshf.c acoshl.c asinh.c asinhf.c asinhl.c \ | ||||
| 	atanh.c atanhf.c atanhl.c fastmath.h | ||||
|  | ||||
| STDIO_DISTFILES = \ | ||||
| 	fopen64.c fseeko64.c ftello64.c lseek64.c \ | ||||
| 	vfscanf.c vfwscanf.c vscanf.c vsscanf.c vswscanf.c vwscanf.c \ | ||||
| 	pformat.c pformat.h snprintf.c vsnprintf.c \ | ||||
| 	snwprintf.c vsnwprintf.c | ||||
|  | ||||
| COMPLEX_DISTFILES = \ | ||||
| @@ -90,7 +92,8 @@ GDTOA_DISTFILES = \ | ||||
| 	arithchk.c dmisc.c dtoa.c  g__fmt.c g_dfmt.c g_ffmt.c g_xfmt.c \ | ||||
| 	gd_arith.h  gd_qnan.h gdtoa.c gdtoa.h gdtoaimp.h gethex.c gmisc.c \ | ||||
| 	hd_init.c hexnan.c  misc.c qnan.c README smisc.c strtodg.c strtodnrp.c \ | ||||
| 	strtof.c strtopx.c sum.c ulp.c mingw_snprintf.c | ||||
| 	strtof.c strtopx.c sum.c ulp.c | ||||
|  | ||||
| CC = @CC@ | ||||
| # FIXME: Which is it, CC or CC_FOR_TARGET? | ||||
| CC_FOR_TARGET = $(CC) | ||||
| @@ -139,7 +142,7 @@ STDLIB_STUB_OBJS = \ | ||||
| STDIO_OBJS = \ | ||||
| 	fopen64.o fseeko64.o ftello64.o lseek64.o \ | ||||
| 	vfscanf.o vfwscanf.o vscanf.o vsscanf.o vswscanf.o vwscanf.o \ | ||||
| 	snwprintf.o vsnwprintf.o | ||||
| 	pformat.o snprintf.o vsnprintf.o snwprintf.o vsnwprintf.o | ||||
| MATH_OBJS = \ | ||||
| 	acosf.o acosl.o asinf.o asinl.o atan2f.o atan2l.o \ | ||||
| 	atanf.o atanl.o cbrt.o cbrtf.o cbrtl.o ceilf.o ceill.o \ | ||||
| @@ -175,8 +178,7 @@ FENV_OBJS = fesetround.o  fegetround.o \ | ||||
| 	feclearexcept.o feholdexcept.o fegetexceptflag.o \ | ||||
| 	feraiseexcept.o fetestexcept.o fesetexceptflag.o | ||||
| POSIX_OBJS = \ | ||||
| 	dirent.o wdirent.o getopt.o ftruncate.o gettimeofday.o \ | ||||
| 	usleep.o \ | ||||
| 	dirent.o wdirent.o getopt.o ftruncate.o gettimeofday.o usleep.o \ | ||||
| 	basename.o dirname.o tsearch.o twalk.o tdelete.o tfind.o | ||||
| REPLACE_OBJS = \ | ||||
| 	mingw-aligned-malloc.o mingw-fseek.o | ||||
| @@ -193,8 +195,7 @@ COMPLEX_OBJS = \ | ||||
| GDTOA_OBJS = \ | ||||
| 	dmisc.o dtoa.o g__fmt.o g_dfmt.o g_ffmt.o g_xfmt.o gdtoa.o \ | ||||
| 	gethex.o gmisc.o hd_init.o hexnan.o misc.o smisc.o \ | ||||
| 	strtodg.o strtodnrp.o strtof.o strtopx.o sum.o ulp.o \ | ||||
| 	mingw_snprintf.o | ||||
| 	strtodg.o strtodnrp.o strtof.o strtopx.o sum.o ulp.o | ||||
|  | ||||
| LIB_OBJS = $(Q8_OBJS)  $(CTYPE_OBJS) $(STDLIB_STUB_OBJS) \ | ||||
| 	$(STDIO_OBJS) $(MATH_OBJS) $(MATH_ROUND_OBJS) \ | ||||
| @@ -252,6 +253,14 @@ distclean: | ||||
| .s.o: | ||||
| 	$(CC) -c  $< -o $@ | ||||
|  | ||||
| # pformat.o needs an explicit build rule; we always build it | ||||
| # assuming __MSVCRT_VERSION__ >= 0x0800, relying on ofmt_stub.s | ||||
| # (in the parent directory) to maintain forward compatibility | ||||
| # for earlier versions of MSVCRT.DLL | ||||
| # | ||||
| PFORMAT_CFLAGS = $(ALL_CFLAGS) -I $(srcdir)/gdtoa -D__MSVCRT_VERSION__=0x0800 | ||||
| pformat.o: pformat.c pformat.h | ||||
| 	$(CC) -c $(PFORMAT_CFLAGS) $(srcdir)/stdio/$*.c -o $@ | ||||
|  | ||||
| # | ||||
| # Dependencies | ||||
| @@ -267,6 +276,9 @@ $(GDTOA_OBJS): gd_arith.h gdtoa.h gdtoaimp.h gd_qnan.h | ||||
|  | ||||
| $(MATH_ROUND_OBJS) $(MATH_LROUND_OBJS) $(MATH_LLROUND_OBJS): round_internal.h | ||||
|  | ||||
| snprintf.o:  snprintf.c  pformat.h | ||||
| vsnprintf.o: vsnprintf.c pformat.h | ||||
|  | ||||
| dist: | ||||
| 	mkdir $(distdir)/mingwex | ||||
| 	chmod 755 $(distdir)/mingwex | ||||
|   | ||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										2511
									
								
								winsup/mingw/mingwex/stdio/pformat.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2511
									
								
								winsup/mingw/mingwex/stdio/pformat.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										90
									
								
								winsup/mingw/mingwex/stdio/pformat.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								winsup/mingw/mingwex/stdio/pformat.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| #ifndef PFORMAT_H | ||||
| /* | ||||
|  * pformat.h | ||||
|  * | ||||
|  * $Id$ | ||||
|  * | ||||
|  * 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 | ||||
|  | ||||
| /* This isn't currently defined therein, | ||||
|  * but is a potential candidate for inclusion in _mingw.h | ||||
|  */ | ||||
| #ifdef __MINGW32__ | ||||
| # define __stringify__(NAME)    #NAME | ||||
| # define __mingw_quoted(NAME)  __stringify__(__mingw_##NAME) | ||||
| # define __mingw_alias(NAME)   __attribute__((alias(__mingw_quoted(NAME)))) NAME | ||||
| #else | ||||
| # define __mingw_alias(NAME)   NAME | ||||
| #endif | ||||
|  | ||||
| /* The following are the declarations specific to the `pformat' API... | ||||
|  */ | ||||
| #define PFORMAT_TO_FILE     0x1000 | ||||
| #define PFORMAT_NOLIMIT     0x2000 | ||||
|  | ||||
| #ifdef __MINGW32__ | ||||
|  /* | ||||
|   * Map MinGW specific function names, for use in place of the generic | ||||
|   * implementation defined equivalent function names. | ||||
|   */ | ||||
| # define __pformat        __mingw_pformat | ||||
|  | ||||
| # 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 | ||||
|  | ||||
| int __cdecl __pformat( int, void *, int, const char *, va_list ) __MINGW_NOTHROW; | ||||
|  | ||||
| #endif /* !defined PFORMAT_H: $RCSfile$Revision$: end of file */ | ||||
							
								
								
									
										44
									
								
								winsup/mingw/mingwex/stdio/snprintf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								winsup/mingw/mingwex/stdio/snprintf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,44 @@ | ||||
| /* snprintf.c | ||||
|  * | ||||
|  * $Id$ | ||||
|  * | ||||
|  * 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 "pformat.h" | ||||
|  | ||||
| int __cdecl __snprintf (char *, size_t, const char *fmt, ...) __MINGW_NOTHROW; | ||||
| int __cdecl __mingw_alias(snprintf) (char *, size_t, const char *, ...) __MINGW_NOTHROW; | ||||
|  | ||||
| int __cdecl __vsnprintf (char *, size_t, const char *fmt, va_list) __MINGW_NOTHROW; | ||||
|  | ||||
| int __cdecl __snprintf( char *buf, size_t length, const char *fmt, ... ) | ||||
| { | ||||
|   va_list argv; va_start( argv, fmt ); | ||||
|   register int retval = __vsnprintf( buf, length, fmt, argv ); | ||||
|   va_end( argv ); | ||||
|   return retval; | ||||
| } | ||||
|  | ||||
| /* $RCSfile$Revision$: end of file */ | ||||
							
								
								
									
										55
									
								
								winsup/mingw/mingwex/stdio/vsnprintf.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								winsup/mingw/mingwex/stdio/vsnprintf.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| /* vsnprintf.c | ||||
|  * | ||||
|  * $Id$ | ||||
|  * | ||||
|  * 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 "pformat.h" | ||||
|  | ||||
| int __cdecl __vsnprintf (char *, size_t, const char *fmt, va_list) __MINGW_NOTHROW; | ||||
| int __cdecl __mingw_alias(vsnprintf) (char *, size_t, const char *, va_list) __MINGW_NOTHROW; | ||||
|  | ||||
| int __cdecl __vsnprintf( char *buf, size_t length, const char *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 < length ? retval : length] = '\0'; | ||||
|  | ||||
|   return retval; | ||||
| } | ||||
|  | ||||
| /* $RCSfile$Revision$: end of file */ | ||||
		Reference in New Issue
	
	Block a user