Commit bd3fbc6b by Kaveh R. Ghazi Committed by Kaveh Ghazi

configure.in (funcs, [...]): Add snprintf and vsnprintf.

	* configure.in (funcs, AC_CHECK_FUNCS): Add snprintf and
	vsnprintf.
	* snprintf.c, vsnprintf.c: New files.
	* Makefile.in (CFILES): Add snprintf.c and vsnprintf.c.
	(CONFIGURED_OFILES): Add snprintf.o and vsnprintf.o.
	Regenerate dependencies.

	* functions.texi, configure, config.in: Regenerated.

From-SVN: r65704
parent a9ecacf6
2003-04-16 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* configure.in (funcs, AC_CHECK_FUNCS): Add snprintf and
vsnprintf.
* snprintf.c, vsnprintf.c: New files.
* Makefile.in (CFILES): Add snprintf.c and vsnprintf.c.
(CONFIGURED_OFILES): Add snprintf.o and vsnprintf.o.
Regenerate dependencies.
* functions.texi, configure, config.in: Regenerated.
2003-04-15 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2003-04-15 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* mempcpy.c, stpcpy.c, stpncpy.c: New files. * mempcpy.c, stpcpy.c, stpncpy.c: New files.
......
...@@ -147,12 +147,12 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \ ...@@ -147,12 +147,12 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
pex-unix.c pex-win32.c \ pex-unix.c pex-win32.c \
physmem.c putenv.c \ physmem.c putenv.c \
random.c regex.c rename.c rindex.c \ random.c regex.c rename.c rindex.c \
safe-ctype.c setenv.c sigsetmask.c sort.c spaces.c \ safe-ctype.c setenv.c sigsetmask.c snprintf.c sort.c spaces.c \
splay-tree.c stpcpy.c stpncpy.c strcasecmp.c strchr.c strdup.c \ splay-tree.c stpcpy.c stpncpy.c strcasecmp.c strchr.c strdup.c \
strerror.c strncasecmp.c strncmp.c strrchr.c strsignal.c \ strerror.c strncasecmp.c strncmp.c strrchr.c strsignal.c \
strstr.c strtod.c strtol.c strtoul.c \ strstr.c strtod.c strtol.c strtoul.c \
ternary.c tmpnam.c \ ternary.c tmpnam.c \
vasprintf.c vfork.c vfprintf.c vprintf.c vsprintf.c \ vasprintf.c vfork.c vfprintf.c vprintf.c vsnprintf.c vsprintf.c \
waitpid.c \ waitpid.c \
xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c xatexit.c xexit.c xmalloc.c xmemdup.c xstrdup.c xstrerror.c
...@@ -191,11 +191,11 @@ CONFIGURED_OFILES = asprintf.o atexit.o \ ...@@ -191,11 +191,11 @@ CONFIGURED_OFILES = asprintf.o atexit.o \
pex-unix.o pex-win32.o \ pex-unix.o pex-win32.o \
putenv.o \ putenv.o \
random.o rename.o rindex.o \ random.o rename.o rindex.o \
setenv.o sigsetmask.o stpcpy.o stpncpy.o strcasecmp.o strchr.o \ setenv.o sigsetmask.o snprintf.o stpcpy.o stpncpy.o strcasecmp.o \
strdup.o strncasecmp.o strncmp.o strrchr.o strstr.o strtod.o \ strchr.o strdup.o strncasecmp.o strncmp.o strrchr.o strstr.o \
strtol.o strtoul.o \ strtod.o strtol.o strtoul.o \
tmpnam.o \ tmpnam.o \
vasprintf.o vfork.o vfprintf.o vprintf.o vsprintf.o \ vasprintf.o vfork.o vfprintf.o vprintf.o vsnprintf.o vsprintf.o \
waitpid.o waitpid.o
# These files are installed if the library has been configured to do so. # These files are installed if the library has been configured to do so.
...@@ -486,6 +486,7 @@ rename.o: config.h $(INCDIR)/ansidecl.h ...@@ -486,6 +486,7 @@ rename.o: config.h $(INCDIR)/ansidecl.h
safe-ctype.o: $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h safe-ctype.o: $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
setenv.o: config.h $(INCDIR)/ansidecl.h setenv.o: config.h $(INCDIR)/ansidecl.h
sigsetmask.o: $(INCDIR)/ansidecl.h sigsetmask.o: $(INCDIR)/ansidecl.h
snprintf.o: $(INCDIR)/ansidecl.h
sort.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \ sort.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h \
$(INCDIR)/sort.h $(INCDIR)/sort.h
spaces.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h spaces.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
...@@ -510,6 +511,7 @@ vasprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h ...@@ -510,6 +511,7 @@ vasprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
vfork.o: $(INCDIR)/ansidecl.h vfork.o: $(INCDIR)/ansidecl.h
vfprintf.o: $(INCDIR)/ansidecl.h vfprintf.o: $(INCDIR)/ansidecl.h
vprintf.o: $(INCDIR)/ansidecl.h vprintf.o: $(INCDIR)/ansidecl.h
vsnprintf.o: config.h $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
vsprintf.o: $(INCDIR)/ansidecl.h vsprintf.o: $(INCDIR)/ansidecl.h
waitpid.o: config.h waitpid.o: config.h
xatexit.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h xatexit.o: $(INCDIR)/ansidecl.h $(INCDIR)/libiberty.h
......
...@@ -150,6 +150,9 @@ ...@@ -150,6 +150,9 @@
/* Define if you have the sigsetmask function. */ /* Define if you have the sigsetmask function. */
#undef HAVE_SIGSETMASK #undef HAVE_SIGSETMASK
/* Define if you have the snprintf function. */
#undef HAVE_SNPRINTF
/* Define if you have the stpcpy function. */ /* Define if you have the stpcpy function. */
#undef HAVE_STPCPY #undef HAVE_STPCPY
...@@ -216,6 +219,9 @@ ...@@ -216,6 +219,9 @@
/* Define if you have the vprintf function. */ /* Define if you have the vprintf function. */
#undef HAVE_VPRINTF #undef HAVE_VPRINTF
/* Define if you have the vsnprintf function. */
#undef HAVE_VSNPRINTF
/* Define if you have the vsprintf function. */ /* Define if you have the vsprintf function. */
#undef HAVE_VSPRINTF #undef HAVE_VSPRINTF
......
...@@ -185,6 +185,7 @@ funcs="$funcs random" ...@@ -185,6 +185,7 @@ funcs="$funcs random"
funcs="$funcs rename" funcs="$funcs rename"
funcs="$funcs rindex" funcs="$funcs rindex"
funcs="$funcs setenv" funcs="$funcs setenv"
funcs="$funcs snprintf"
funcs="$funcs sigsetmask" funcs="$funcs sigsetmask"
funcs="$funcs stpcpy" funcs="$funcs stpcpy"
funcs="$funcs stpncpy" funcs="$funcs stpncpy"
...@@ -201,6 +202,7 @@ funcs="$funcs tmpnam" ...@@ -201,6 +202,7 @@ funcs="$funcs tmpnam"
funcs="$funcs vasprintf" funcs="$funcs vasprintf"
funcs="$funcs vfprintf" funcs="$funcs vfprintf"
funcs="$funcs vprintf" funcs="$funcs vprintf"
funcs="$funcs vsnprintf"
funcs="$funcs vsprintf" funcs="$funcs vsprintf"
funcs="$funcs waitpid" funcs="$funcs waitpid"
...@@ -221,7 +223,7 @@ if test "x" = "y"; then ...@@ -221,7 +223,7 @@ if test "x" = "y"; then
AC_CHECK_FUNCS(strcasecmp setenv stpcpy stpncpy strchr strdup strncasecmp strrchr strstr) AC_CHECK_FUNCS(strcasecmp setenv stpcpy stpncpy strchr strdup strncasecmp strrchr strstr)
AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf) AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal) AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs) AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs snprintf vsnprintf)
AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl) AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl)
AC_CHECK_FUNCS(realpath canonicalize_file_name) AC_CHECK_FUNCS(realpath canonicalize_file_name)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.]) AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
......
...@@ -673,6 +673,19 @@ be the value @code{1}). ...@@ -673,6 +673,19 @@ be the value @code{1}).
@end deftypefn @end deftypefn
@c snprintf.c:28
@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
This function is similar to sprintf, but it will print at most @var{n}
characters. On error the return value is -1, otherwise it returns the
number of characters that would have been printed had @var{n} been
sufficiently large, regardless of the actual value of @var{n}. Note
some pre-C99 system libraries do not implement this correctly so users
cannot generally rely on the return value if the system version of
this function is used.
@end deftypefn
@c spaces.c:22 @c spaces.c:22
@deftypefn Extension char* spaces (int @var{count}) @deftypefn Extension char* spaces (int @var{count})
...@@ -929,6 +942,19 @@ nonstandard but common function @code{_doprnt}. ...@@ -929,6 +942,19 @@ nonstandard but common function @code{_doprnt}.
@end deftypefn @end deftypefn
@c vsnprintf.c:28
@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
This function is similar to vsprintf, but it will print at most
@var{n} characters. On error the return value is -1, otherwise it
returns the number of characters that would have been printed had
@var{n} been sufficiently large, regardless of the actual value of
@var{n}. Note some pre-C99 system libraries do not implement this
correctly so users cannot generally rely on the return value if the
system version of this function is used.
@end deftypefn
@c waitpid.c:3 @c waitpid.c:3
@deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int) @deftypefn Supplemental int waitpid (int @var{pid}, int *@var{status}, int)
......
/* Implement the snprintf function.
Copyright (C) 2003 Free Software Foundation, Inc.
Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
This file is part of the libiberty library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/*
@deftypefn Supplemental int snprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, ...)
This function is similar to sprintf, but it will print at most @var{n}
characters. On error the return value is -1, otherwise it returns the
number of characters that would have been printed had @var{n} been
sufficiently large, regardless of the actual value of @var{n}. Note
some pre-C99 system libraries do not implement this correctly so users
cannot generally rely on the return value if the system version of
this function is used.
@end deftypefn
*/
#include "ansidecl.h"
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#include <stddef.h>
#else
#include <varargs.h>
#define size_t unsigned long
#endif
int vsnprintf PARAMS ((char *, size_t, const char *, va_list));
int
snprintf VPARAMS ((char *s, size_t n, const char *format, ...))
{
int result;
VA_OPEN (ap, format);
VA_FIXEDARG (ap, char *, s);
VA_FIXEDARG (ap, size_t, n);
VA_FIXEDARG (ap, const char *, format);
result = vsnprintf (s, n, format, ap);
VA_CLOSE (ap);
return result;
}
/* Implement the vsnprintf function.
Copyright (C) 2003 Free Software Foundation, Inc.
Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
This file is part of the libiberty library. This library is free
software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, if you link this library with files
compiled with a GNU compiler to produce an executable, this does not cause
the resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why
the executable file might be covered by the GNU General Public License. */
/*
@deftypefn Supplemental int vsnprintf (char *@var{buf}, size_t @var{n}, const char *@var{format}, va_list @var{ap})
This function is similar to vsprintf, but it will print at most
@var{n} characters. On error the return value is -1, otherwise it
returns the number of characters that would have been printed had
@var{n} been sufficiently large, regardless of the actual value of
@var{n}. Note some pre-C99 system libraries do not implement this
correctly so users cannot generally rely on the return value if the
system version of this function is used.
@end deftypefn
*/
#include "config.h"
#include "ansidecl.h"
#ifdef ANSI_PROTOTYPES
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#include "libiberty.h"
/* This implementation relies on a working vasprintf. */
int
vsnprintf (s, n, format, ap)
char * s;
size_t n;
const char *format;
va_list ap;
{
char *buf = 0;
int result = vasprintf (&buf, format, ap);
if (!buf)
return -1;
if (result < 0)
{
free (buf);
return -1;
}
result = strlen (buf);
if (n > 0)
{
strncpy (s, buf, n);
if (n - 1 < (size_t) result)
s[n - 1] = 0;
}
free (buf);
return result;
}
#ifdef TEST
/* Set the buffer to a known state. */
#define CLEAR(BUF) do { memset ((BUF), 'X', sizeof (BUF)); (BUF)[14] = '\0'; } while (0)
/* For assertions. */
#define VERIFY(P) do { if (!(P)) abort(); } while (0)
static int ATTRIBUTE_PRINTF_3
checkit VPARAMS ((char *s, size_t n, const char *format, ...))
{
int result;
VA_OPEN (ap, format);
VA_FIXEDARG (ap, char *, s);
VA_FIXEDARG (ap, size_t, n);
VA_FIXEDARG (ap, const char *, format);
result = vsnprintf (s, n, format, ap);
VA_CLOSE (ap);
return result;
}
extern int main PARAMS ((void));
int
main ()
{
char buf[128];
int status;
CLEAR (buf);
status = checkit (buf, 10, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "foobar:9") == 0);
CLEAR (buf);
status = checkit (buf, 9, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "foobar:9") == 0);
CLEAR (buf);
status = checkit (buf, 8, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "foobar:") == 0);
CLEAR (buf);
status = checkit (buf, 7, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "foobar") == 0);
CLEAR (buf);
status = checkit (buf, 6, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "fooba") == 0);
CLEAR (buf);
status = checkit (buf, 2, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "f") == 0);
CLEAR (buf);
status = checkit (buf, 1, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "") == 0);
CLEAR (buf);
status = checkit (buf, 0, "%s:%d", "foobar", 9);
VERIFY (status==8 && strcmp (buf, "XXXXXXXXXXXXXX") == 0);
return 0;
}
#endif /* TEST */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment