This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sniprintf [PATCH]


sniprintf is conspicuosly missing. This patch adds it in the most
obvious way. Perhaps instead sniprintf.c should be generated from
snprintf.c automatically. This patch does not address vsniprintf,
which is also missing.

Please cc me in your reply. Cheers,
Shaun

2004-11-13  Shaun Jackman  <sjackman@gmail.com>

	* libc/include/stdio.h: Add sniprintf.
	* libc/stdio/Makefile.am: Add sniprintf.c.
	* libc/stdio/sniprintf.c: New.
diff -urN newlib-1.12.0.orig/newlib/libc/include/stdio.h newlib-1.12.0/newlib/libc/include/stdio.h
--- newlib-1.12.0.orig/newlib/libc/include/stdio.h	2003-08-26 11:09:42.000000000 -0700
+++ newlib-1.12.0/newlib/libc/include/stdio.h	2004-11-13 16:55:36.000000000 -0800
@@ -240,6 +240,7 @@
 #ifndef _REENT_ONLY
 int	_EXFUN(fcloseall, (_VOID));
 int	_EXFUN(snprintf, (char *, size_t, const char *, ...));
+int	_EXFUN(sniprintf, (char *, size_t, const char *, ...));
 #endif
 #endif
 
diff -urN newlib-1.12.0.orig/newlib/libc/stdio/Makefile.am newlib-1.12.0/newlib/libc/stdio/Makefile.am
--- newlib-1.12.0.orig/newlib/libc/stdio/Makefile.am	2003-01-06 17:45:32.000000000 -0800
+++ newlib-1.12.0/newlib/libc/stdio/Makefile.am	2004-11-13 17:14:09.000000000 -0800
@@ -58,6 +58,7 @@
 	setlinebuf.c 			\
 	setvbuf.c 			\
 	siprintf.c 			\
+	sniprintf.c			\
 	snprintf.c			\
 	sprintf.c 			\
 	sscanf.c 			\
diff -urN newlib-1.12.0.orig/newlib/libc/stdio/Makefile.in newlib-1.12.0/newlib/libc/stdio/Makefile.in
--- newlib-1.12.0.orig/newlib/libc/stdio/Makefile.in	2004-01-27 15:26:25.000000000 -0800
+++ newlib-1.12.0/newlib/libc/stdio/Makefile.in	2004-11-13 16:55:48.000000000 -0800
@@ -110,7 +110,7 @@
 
 INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS)
 
-GENERAL_SOURCES =  	clearerr.c 				fclose.c 				fdopen.c 				feof.c 					ferror.c 				fflush.c 				fgetc.c 				fgetpos.c 				fgets.c 				fileno.c				findfp.c 				fiprintf.c 				flags.c 				fopen.c 				fprintf.c 				fputc.c 				fputs.c 				fread.c 				freopen.c 				fscanf.c 				fseek.c 				fsetpos.c 				ftell.c 				fvwrite.c 				fwalk.c 				fwrite.c 				getc.c 					getchar.c 				getc_u.c				getchar_u.c				getdelim.c				getline.c				gets.c 					iprintf.c 				makebuf.c				perror.c 				printf.c 				putc.c 					putchar.c 				putc_u.c				putchar_u.c				puts.c 					refill.c 				remove.c 				rename.c 				rewind.c 				rget.c 					scanf.c 				setbuf.c 				setbuffer.c 				setlinebuf.c 				setvbuf.c 				siprintf.c 				snprintf.c				sprintf.c 				sscanf.c 				stdio.c 				tmpfile.c 				tmpnam.c 				ungetc.c 				vfscanf.c 				vprintf.c 				vscanf.c				vsnprintf.c				vsprintf.c 				vsscanf.c				wbuf.c 					wsetup.c 
+GENERAL_SOURCES =  	clearerr.c 				fclose.c 				fdopen.c 				feof.c 					ferror.c 				fflush.c 				fgetc.c 				fgetpos.c 				fgets.c 				fileno.c				findfp.c 				fiprintf.c 				flags.c 				fopen.c 				fprintf.c 				fputc.c 				fputs.c 				fread.c 				freopen.c 				fscanf.c 				fseek.c 				fsetpos.c 				ftell.c 				fvwrite.c 				fwalk.c 				fwrite.c 				getc.c 					getchar.c 				getc_u.c				getchar_u.c				getdelim.c				getline.c				gets.c 					iprintf.c 				makebuf.c				perror.c 				printf.c 				putc.c 					putchar.c 				putc_u.c				putchar_u.c				puts.c 					refill.c 				remove.c 				rename.c 				rewind.c 				rget.c 					scanf.c 				setbuf.c 				setbuffer.c 				setlinebuf.c 				setvbuf.c 				siprintf.c 				sniprintf.c snprintf.c				sprintf.c 				sscanf.c 				stdio.c 				tmpfile.c 				tmpnam.c 				ungetc.c 				vfscanf.c 				vprintf.c 				vscanf.c				vsnprintf.c				vsprintf.c 				vsscanf.c				wbuf.c 					wsetup.c 
 
 @ELIX_LEVEL_1_TRUE@LIB_OBJS = 
 @ELIX_LEVEL_1_FALSE@LIB_OBJS = 	asprintf.$(oext)			fcloseall.$(oext)			fseeko.$(oext) 				ftello.$(oext) 				getw.$(oext)				mktemp.$(oext) 				putw.$(oext) 				vasprintf.$(oext)
@@ -169,7 +169,7 @@
 @USE_LIBTOOL_FALSE@rget.$(OBJEXT) scanf.$(OBJEXT) setbuf.$(OBJEXT) \
 @USE_LIBTOOL_FALSE@setbuffer.$(OBJEXT) setlinebuf.$(OBJEXT) \
 @USE_LIBTOOL_FALSE@setvbuf.$(OBJEXT) siprintf.$(OBJEXT) \
-@USE_LIBTOOL_FALSE@snprintf.$(OBJEXT) sprintf.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@sniprintf.$(OBJEXT) snprintf.$(OBJEXT) sprintf.$(OBJEXT) \
 @USE_LIBTOOL_FALSE@sscanf.$(OBJEXT) stdio.$(OBJEXT) tmpfile.$(OBJEXT) \
 @USE_LIBTOOL_FALSE@tmpnam.$(OBJEXT) ungetc.$(OBJEXT) vfscanf.$(OBJEXT) \
 @USE_LIBTOOL_FALSE@vprintf.$(OBJEXT) vscanf.$(OBJEXT) \
@@ -188,7 +188,7 @@
 @USE_LIBTOOL_TRUE@putchar.lo putc_u.lo putchar_u.lo puts.lo refill.lo \
 @USE_LIBTOOL_TRUE@remove.lo rename.lo rewind.lo rget.lo scanf.lo \
 @USE_LIBTOOL_TRUE@setbuf.lo setbuffer.lo setlinebuf.lo setvbuf.lo \
-@USE_LIBTOOL_TRUE@siprintf.lo snprintf.lo sprintf.lo sscanf.lo stdio.lo \
+@USE_LIBTOOL_TRUE@siprintf.lo sniprintf.lo snprintf.lo sprintf.lo sscanf.lo stdio.lo \
 @USE_LIBTOOL_TRUE@tmpfile.lo tmpnam.lo ungetc.lo vfscanf.lo vprintf.lo \
 @USE_LIBTOOL_TRUE@vscanf.lo vsnprintf.lo vsprintf.lo vsscanf.lo wbuf.lo \
 @USE_LIBTOOL_TRUE@wsetup.lo
diff -urN newlib-1.12.0.orig/newlib/libc/stdio/sniprintf.c newlib-1.12.0/newlib/libc/stdio/sniprintf.c
--- newlib-1.12.0.orig/newlib/libc/stdio/sniprintf.c	1969-12-31 16:00:00.000000000 -0800
+++ newlib-1.12.0/newlib/libc/stdio/sniprintf.c	2004-11-13 16:50:54.000000000 -0800
@@ -0,0 +1,95 @@
+/* doc in sprintf.c */
+
+/* This code created by modifying sprintf.c so copyright inherited. */
+
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#include <stdio.h>
+#ifdef _HAVE_STDC
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <limits.h>
+#include <_ansi.h>
+#include "local.h"
+
+int
+#ifdef _HAVE_STDC
+_DEFUN (_sniprintf_r, (ptr, str, size, fmt), struct _reent *ptr _AND char *str _AND size_t size _AND _CONST char *fmt _DOTS)
+#else
+_sniprintf_r (ptr, str, size, fmt, va_alist)
+     struct _reent *ptr;
+     char *str;
+     size_t size;
+     _CONST char *fmt;
+     va_dcl
+#endif
+{
+  int ret;
+  va_list ap;
+  FILE f;
+
+  f._flags = __SWR | __SSTR;
+  f._bf._base = f._p = (unsigned char *) str;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+#ifdef _HAVE_STDC
+  va_start (ap, fmt);
+#else
+  va_start (ap);
+#endif
+  ret = _vfiprintf_r (ptr, &f, fmt, ap);
+  va_end (ap);
+  if (size > 0)
+    *f._p = 0;
+  return (ret);
+}
+
+#ifndef _REENT_ONLY
+
+int
+#ifdef _HAVE_STDC
+_DEFUN (sniprintf, (str, size, fmt), char *str _AND size_t size _AND _CONST char *fmt _DOTS)
+#else
+sniprintf (str, size, fmt, va_alist)
+     char *str;
+     size_t size;
+     _CONST char *fmt;
+     va_dcl
+#endif
+{
+  int ret;
+  va_list ap;
+  FILE f;
+
+  f._flags = __SWR | __SSTR;
+  f._bf._base = f._p = (unsigned char *) str;
+  f._bf._size = f._w = (size > 0 ? size - 1 : 0);
+#ifdef _HAVE_STDC
+  va_start (ap, fmt);
+#else
+  va_start (ap);
+#endif
+  ret = _vfiprintf_r (_REENT, &f, fmt, ap);
+  va_end (ap);
+  if (size > 0)
+    *f._p = 0;
+  return (ret);
+}
+
+#endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]