aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2004-11-20 01:42:35 +0000
committerJeff Johnston <jjohnstn@redhat.com>2004-11-20 01:42:35 +0000
commit0f0fcb042a8e8a80433d7b372cf5a1a3b603d55f (patch)
tree56183de69337ea168d6583de6d282a1e0489586f /newlib
parent225699ae46a8b4089f9c18ecdcbc0353d48d6781 (diff)
downloadnewlib-0f0fcb042a8e8a80433d7b372cf5a1a3b603d55f.zip
newlib-0f0fcb042a8e8a80433d7b372cf5a1a3b603d55f.tar.gz
newlib-0f0fcb042a8e8a80433d7b372cf5a1a3b603d55f.tar.bz2
2004-11-19 Shaun Jackman <sjackman@gmail.com>
* libc/include/stdio.h: Add sniprintf. * libc/stdio/Makefile.am: Add sniprintf.c. * libc/stdio/Makefile.in: Regenerated. * libc/stdio/sniprintf.c: New file. * libc/stdio/stdio.tex: Add sniprintf.
Diffstat (limited to 'newlib')
-rw-r--r--newlib/ChangeLog8
-rw-r--r--newlib/libc/include/stdio.h1
-rw-r--r--newlib/libc/stdio/Makefile.am2
-rw-r--r--newlib/libc/stdio/Makefile.in20
-rw-r--r--newlib/libc/stdio/sniprintf.c142
-rw-r--r--newlib/libc/stdio/stdio.tex6
6 files changed, 168 insertions, 11 deletions
diff --git a/newlib/ChangeLog b/newlib/ChangeLog
index 8b8cf4d..2d17000 100644
--- a/newlib/ChangeLog
+++ b/newlib/ChangeLog
@@ -1,3 +1,11 @@
+2004-11-19 Shaun Jackman <sjackman@gmail.com>
+
+ * libc/include/stdio.h: Add sniprintf.
+ * libc/stdio/Makefile.am: Add sniprintf.c.
+ * libc/stdio/Makefile.in: Regenerated.
+ * libc/stdio/sniprintf.c: New file.
+ * libc/stdio/stdio.tex: Add sniprintf.
+
2004-11-17 Christopher Faylor <cgf@timesys.com>
* libc/stdio/refill.c (__srefill): Try again after EOF on Cygwin. Clear
diff --git a/newlib/libc/include/stdio.h b/newlib/libc/include/stdio.h
index 86c948f..c33dfe0 100644
--- a/newlib/libc/include/stdio.h
+++ b/newlib/libc/include/stdio.h
@@ -240,6 +240,7 @@ int _EXFUN(vsscanf, (const char *, const char *, __VALIST));
#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 --git a/newlib/libc/stdio/Makefile.am b/newlib/libc/stdio/Makefile.am
index 37911ef..c8d689e 100644
--- a/newlib/libc/stdio/Makefile.am
+++ b/newlib/libc/stdio/Makefile.am
@@ -58,6 +58,7 @@ GENERAL_SOURCES = \
setlinebuf.c \
setvbuf.c \
siprintf.c \
+ sniprintf.c \
snprintf.c \
sprintf.c \
sscanf.c \
@@ -167,6 +168,7 @@ CHEWOUT_FILES = \
setlinebuf.def \
setvbuf.def \
siprintf.def \
+ sniprintf.def \
sprintf.def \
sscanf.def \
tmpfile.def \
diff --git a/newlib/libc/stdio/Makefile.in b/newlib/libc/stdio/Makefile.in
index c876b93..c79f5cd 100644
--- a/newlib/libc/stdio/Makefile.in
+++ b/newlib/libc/stdio/Makefile.in
@@ -110,7 +110,7 @@ AUTOMAKE_OPTIONS = cygnus
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)
@@ -132,7 +132,7 @@ libstdio_la_LDFLAGS = -Xcompiler -nostdlib
@USE_LIBTOOL_FALSE@lib_a_LIBADD = $(LIBADD_OBJS) $(LIB_OBJS)
@USE_LIBTOOL_FALSE@lib_a_DEPENDENCIES = $(LIBADD_OBJS) $(LIB_OBJS)
-CHEWOUT_FILES = clearerr.def fclose.def fcloseall.def fdopen.def feof.def ferror.def fflush.def fgetc.def fgetpos.def fgets.def fileno.def fiprintf.def fopen.def fputc.def fputs.def fread.def freopen.def fseek.def fsetpos.def ftell.def fwrite.def getc.def getchar.def getc_u.def getchar_u.def getdelim.def getline.def gets.def getw.def iprintf.def mktemp.def perror.def putc.def putchar.def putc_u.def putchar_u.def puts.def putw.def remove.def rename.def rewind.def setbuf.def setbuffer.def setlinebuf.def setvbuf.def siprintf.def sprintf.def sscanf.def tmpfile.def tmpnam.def vfprintf.def vfscanf.def
+CHEWOUT_FILES = clearerr.def fclose.def fcloseall.def fdopen.def feof.def ferror.def fflush.def fgetc.def fgetpos.def fgets.def fileno.def fiprintf.def fopen.def fputc.def fputs.def fread.def freopen.def fseek.def fsetpos.def ftell.def fwrite.def getc.def getchar.def getc_u.def getchar_u.def getdelim.def getline.def gets.def getw.def iprintf.def mktemp.def perror.def putc.def putchar.def putc_u.def putchar_u.def puts.def putw.def remove.def rename.def rewind.def setbuf.def setbuffer.def setlinebuf.def setvbuf.def siprintf.def sniprintf.def sprintf.def sscanf.def tmpfile.def tmpnam.def vfprintf.def vfscanf.def
SUFFIXES = .def
@@ -169,10 +169,10 @@ LIBS = @LIBS@
@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@sscanf.$(OBJEXT) stdio.$(OBJEXT) tmpfile.$(OBJEXT) \
-@USE_LIBTOOL_FALSE@tmpnam.$(OBJEXT) ungetc.$(OBJEXT) vfscanf.$(OBJEXT) \
-@USE_LIBTOOL_FALSE@vprintf.$(OBJEXT) vscanf.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@sniprintf.$(OBJEXT) snprintf.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@sprintf.$(OBJEXT) sscanf.$(OBJEXT) stdio.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@tmpfile.$(OBJEXT) tmpnam.$(OBJEXT) ungetc.$(OBJEXT) \
+@USE_LIBTOOL_FALSE@vfscanf.$(OBJEXT) vprintf.$(OBJEXT) vscanf.$(OBJEXT) \
@USE_LIBTOOL_FALSE@vsnprintf.$(OBJEXT) vsprintf.$(OBJEXT) \
@USE_LIBTOOL_FALSE@vsscanf.$(OBJEXT) wbuf.$(OBJEXT) wsetup.$(OBJEXT)
LTLIBRARIES = $(noinst_LTLIBRARIES)
@@ -188,10 +188,10 @@ LTLIBRARIES = $(noinst_LTLIBRARIES)
@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@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
+@USE_LIBTOOL_TRUE@siprintf.lo sniprintf.lo snprintf.lo sprintf.lo \
+@USE_LIBTOOL_TRUE@sscanf.lo stdio.lo tmpfile.lo tmpnam.lo ungetc.lo \
+@USE_LIBTOOL_TRUE@vfscanf.lo vprintf.lo vscanf.lo vsnprintf.lo \
+@USE_LIBTOOL_TRUE@vsprintf.lo vsscanf.lo wbuf.lo wsetup.lo
CFLAGS = @CFLAGS@
COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
diff --git a/newlib/libc/stdio/sniprintf.c b/newlib/libc/stdio/sniprintf.c
new file mode 100644
index 0000000..042a42e
--- /dev/null
+++ b/newlib/libc/stdio/sniprintf.c
@@ -0,0 +1,142 @@
+/*
+ * 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.
+ */
+
+/* This code created by modifying snprintf.c so copyright inherited. */
+
+/*
+FUNCTION
+<<sniprintf>>---write formatted output (integer only)
+
+INDEX
+ sniprintf
+
+ANSI_SYNOPSIS
+ #include <stdio.h>
+
+ int sniprintf(char *<[str]>, size_t <[size]>, const char *<[format]> [, <[arg]>, ...]);
+
+TRAD_SYNOPSIS
+ #include <stdio.h>
+
+ int sniprintf(<[str]>, size_t <[size]>, <[format]> [, <[arg]>, ...]);
+ char *<[str]>;
+ size_t <[size]>;
+ char *<[format]>;
+
+DESCRIPTION
+<<sniprintf>> is a restricted version of <<snprintf>>: it has the same
+arguments and behavior, save that it cannot perform any floating-point
+formatting: the <<f>>, <<g>>, <<G>>, <<e>>, and <<F>> type specifiers
+are not recognized.
+
+RETURNS
+ <<sniprintf>> returns the number of bytes in the output string,
+ save that the concluding <<NULL>> is not counted.
+ <<sniprintf>> returns when the end of the format string is
+ encountered.
+
+PORTABILITY
+<<sniprintf>> is not required by ANSI C.
+
+Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
+<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
+*/
+
+#include <_ansi.h>
+#include <reent.h>
+#include <stdio.h>
+#ifdef _HAVE_STDC
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <limits.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);
+ f._file = -1; /* No file. */
+#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);
+ f._file = -1; /* No file. */
+#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
diff --git a/newlib/libc/stdio/stdio.tex b/newlib/libc/stdio/stdio.tex
index 728831c..f5f092f 100644
--- a/newlib/libc/stdio/stdio.tex
+++ b/newlib/libc/stdio/stdio.tex
@@ -69,7 +69,8 @@ structure.
* setbuffer:: Specify full buffering for a file or stream with size
* setlinebuf:: Specify line buffering for a file or stream
* setvbuf:: Specify buffering for a file or stream
-* siprintf:: Write formatted output (integer only)
+* siprintf:: Write formatted output to string (integer only)
+* sniprintf:: Write formatted output to string up to max size (integer only)
* printf:: Write formatted output
* scanf:: Scan and format input
* tmpfile:: Create a temporary file
@@ -217,6 +218,9 @@ structure.
@include stdio/siprintf.def
@page
+@include stdio/sniprintf.def
+
+@page
@include stdio/sprintf.def
@page