[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] snprintf (was: Re: vasnprintf problem)
From: |
Simon Josefsson |
Subject: |
[Bug-gnulib] snprintf (was: Re: vasnprintf problem) |
Date: |
Tue, 21 Sep 2004 16:44:23 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
Bruno Haible <address@hidden> writes:
> Simon Josefsson wrote:
>> configure.ac:14: gl_AC_HEADER_INTTYPES_H is required by...
>> m4/intmax_t.m4:63: gt_AC_TYPE_INTMAX_T is expanded from...
>
> It was a missing dependency. Should be fixed now. Thanks.
Great. So here is snprintf. I have not really tested it, but that
will be easier once it is integrated. I don't anticipate there will
be major problems with it.
2004-09-21 Simon Josefsson <address@hidden>
* MODULES.html.sh (Enhancements for POSIX:2001 functions): Add
snprintf.
* modules/snprintf: New file.
2004-09-21 Simon Josefsson <address@hidden>
* snprintf.h, snprintf.c: New file.
2004-09-21 Simon Josefsson <address@hidden>
* snprintf.m4: New file.
Index: lib/snprintf.h
===================================================================
RCS file: lib/snprintf.h
diff -N lib/snprintf.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/snprintf.h 21 Sep 2004 14:43:59 -0000
@@ -0,0 +1,29 @@
+/* Formatted output to strings.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ This program 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 program 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 this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef SNPRINTF_H
+#define SNPRINTF_H
+
+/* Get snprintf declaration, if available. */
+#include <stdio.h>
+
+#if defined HAVE_DECL_SNPRINTF && !HAVE_DECL_SNPRINTF
+int snprintf(char *str, size_t size, const char *format, ...);
+#endif
+
+#endif /* SNPRINTF_H */
Index: lib/snprintf.c
===================================================================
RCS file: lib/snprintf.c
diff -N lib/snprintf.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ lib/snprintf.c 21 Sep 2004 14:43:59 -0000
@@ -0,0 +1,51 @@
+/* Formatted output to strings.
+ Copyright (C) 2004 Free Software Foundation, Inc.
+ Written by Simon Josefsson.
+
+ This program 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 program 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 this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Get specification. */
+#include "snprintf.h"
+
+/* Get vasnprintf. */
+#include "vasnprintf.h"
+
+/* Get MIN. */
+#include <minmax.h>
+
+/* Print formatted output to string STR. Similar to sprintf, but
+ additional length SIZE limit how much is written into STR. Returns
+ string length of formatted string (which may be larger than SIZE).
+ STR may be NULL, in which case nothing will be written. On error,
+ return a negative value. */
+int
+snprintf (char *str, size_t size, const char *format, ...)
+{
+ size_t len;
+ char *out = vasnprintf (NULL, &len, format, args);
+
+ if (!out)
+ return -1;
+
+ if (str)
+ memcpy (str, out, MIN (len, size));
+ free (out);
+
+ return len;
+}
Index: m4/snprintf.m4
===================================================================
RCS file: m4/snprintf.m4
diff -N m4/snprintf.m4
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ m4/snprintf.m4 21 Sep 2004 14:43:59 -0000
@@ -0,0 +1,17 @@
+# sprintf.m4 serial 1
+dnl Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_FUNC_SNPRINTF],
+[
+ AC_REPLACE_FUNCS(snprintf)
+ AC_CHECK_DECLS_ONCE(snprintf)
+ gl_PREREQ_SNPRINTF
+])
+
+# Prerequisites of lib/snprintf.c.
+AC_DEFUN([gl_PREREQ_SNPRINTF], [:])
Index: modules/snprintf
===================================================================
RCS file: modules/snprintf
diff -N modules/snprintf
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ modules/snprintf 21 Sep 2004 14:43:59 -0000
@@ -0,0 +1,23 @@
+Description:
+snprintf() function: print formatted output to a fixed length string
+
+Files:
+lib/snprintf.h
+lib/snprintf.c
+m4/snprintf.m4
+
+Depends-on:
+vasnprintf
+minmax
+
+configure.ac:
+gl_FUNC_SNPRINTF
+
+Makefile.am:
+lib_SOURCES += snprintf.h
+
+Include:
+"snprintf.h"
+
+Maintainer:
+Simon Josefsson
Index: MODULES.html.sh
===================================================================
RCS file: /cvsroot/gnulib/gnulib/MODULES.html.sh,v
retrieving revision 1.60
diff -u -p -r1.60 MODULES.html.sh
--- MODULES.html.sh 8 Sep 2004 12:43:11 -0000 1.60
+++ MODULES.html.sh 21 Sep 2004 14:43:59 -0000
@@ -1734,6 +1735,7 @@ func_all_modules ()
func_module regex
func_module rename
func_module rmdir
+ func_module snprintf
func_module utime
func_end_table
- [Bug-gnulib] vasnprintf problem, Simon Josefsson, 2004/09/21
- Re: [Bug-gnulib] vasnprintf problem, Bruno Haible, 2004/09/21
- [Bug-gnulib] snprintf (was: Re: vasnprintf problem),
Simon Josefsson <=
- Re: [Bug-gnulib] snprintf (was: Re: vasnprintf problem), Bruno Haible, 2004/09/21
- [Bug-gnulib] Re: snprintf, Simon Josefsson, 2004/09/21
- [Bug-gnulib] Re: snprintf, Simon Josefsson, 2004/09/30
- Re: [Bug-gnulib] Re: snprintf, Paul Eggert, 2004/09/30
- [Bug-gnulib] Re: snprintf, Simon Josefsson, 2004/09/30
- [Bug-gnulib] Re: snprintf, Simon Josefsson, 2004/09/30