]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Add.
authorSimon Josefsson <simon@josefsson.org>
Fri, 9 Feb 2007 14:08:43 +0000 (14:08 +0000)
committerSimon Josefsson <simon@josefsson.org>
Fri, 9 Feb 2007 14:08:43 +0000 (14:08 +0000)
lgl/Makefile.am
lgl/asprintf.c [new file with mode: 0644]
lgl/m4/gnulib-cache.m4
lgl/m4/gnulib-comp.m4
lgl/m4/vasprintf.m4 [new file with mode: 0644]
lgl/vasprintf.c [new file with mode: 0644]
lgl/vasprintf.h [new file with mode: 0644]

index 993bfc88ceb0189bae342852329e2c357487b063..7ad392bb3822310b19150269142c5bd48495cc29 100644 (file)
@@ -9,7 +9,7 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by: gnulib-tool --import --dir=. --lib=liblgnu --source-base=lgl --m4-base=lgl/m4 --doc-base=doc --aux-dir=. --lgpl --libtool --macro-prefix=lgl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd
+# Reproduce by: gnulib-tool --import --dir=. --lib=liblgnu --source-base=lgl --m4-base=lgl/m4 --doc-base=doc --aux-dir=. --lgpl --libtool --macro-prefix=lgl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd vasprintf
 
 AUTOMAKE_OPTIONS = 1.5 gnits
 
@@ -415,6 +415,15 @@ EXTRA_liblgnu_la_SOURCES += asnprintf.c printf-args.c printf-parse.c vasnprintf.
 
 ## end   gnulib module vasnprintf
 
+## begin gnulib module vasprintf
+
+
+EXTRA_DIST += asprintf.c vasprintf.c vasprintf.h
+
+EXTRA_liblgnu_la_SOURCES += asprintf.c vasprintf.c
+
+## end   gnulib module vasprintf
+
 ## begin gnulib module wchar
 
 BUILT_SOURCES += $(WCHAR_H)
diff --git a/lgl/asprintf.c b/lgl/asprintf.c
new file mode 100644 (file)
index 0000000..a9293aa
--- /dev/null
@@ -0,0 +1,35 @@
+/* Formatted output to strings.
+   Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "vasprintf.h"
+
+#include <stdarg.h>
+
+int
+asprintf (char **resultp, const char *format, ...)
+{
+  va_list args;
+  int result;
+
+  va_start (args, format);
+  result = vasprintf (resultp, format, args);
+  va_end (args);
+  return result;
+}
index da31ed28473f9c84da060495ba70cf432ffa99da..be731f8ccae6333da657f2f1d90251d630b6c700 100644 (file)
 
 
 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --lib=liblgnu --source-base=lgl --m4-base=lgl/m4 --doc-base=doc --aux-dir=. --lgpl --libtool --macro-prefix=lgl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd
+#   gnulib-tool --import --dir=. --lib=liblgnu --source-base=lgl --m4-base=lgl/m4 --doc-base=doc --aux-dir=. --lgpl --libtool --macro-prefix=lgl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd vasprintf
 
 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([])
-gl_MODULES([gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd])
+gl_MODULES([gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 gettext memmem memmove minmax read-file snprintf socklen stdint strverscmp sys_socket sys_stat time_r unistd vasprintf])
 gl_AVOID([])
 gl_SOURCE_BASE([lgl])
 gl_M4_BASE([lgl/m4])
index 7bd2186762a5f9891003a7f8b97c392bae6c3eee..63f05212f3c5f22e695d18a808610638469266fd 100644 (file)
@@ -89,6 +89,7 @@ AC_DEFUN([lgl_INIT],
   gl_TIME_R
   gl_HEADER_UNISTD
   gl_FUNC_VASNPRINTF
+  gl_FUNC_VASPRINTF
   gl_WCHAR_H
   gl_XSIZE
   m4_popdef([AC_LIBSOURCES])
@@ -135,6 +136,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   lib/arctwo.c
   lib/arctwo.h
   lib/asnprintf.c
+  lib/asprintf.c
   lib/des.c
   lib/des.h
   lib/dummy.c
@@ -183,6 +185,8 @@ AC_DEFUN([lgl_FILE_LIST], [
   lib/unistd_.h
   lib/vasnprintf.c
   lib/vasnprintf.h
+  lib/vasprintf.c
+  lib/vasprintf.h
   lib/wchar_.h
   lib/xsize.h
   m4/absolute-header.m4
@@ -256,6 +260,7 @@ AC_DEFUN([lgl_FILE_LIST], [
   m4/ulonglong.m4
   m4/unistd_h.m4
   m4/vasnprintf.m4
+  m4/vasprintf.m4
   m4/visibility.m4
   m4/wchar.m4
   m4/wchar_t.m4
diff --git a/lgl/m4/vasprintf.m4 b/lgl/m4/vasprintf.m4
new file mode 100644 (file)
index 0000000..18ca632
--- /dev/null
@@ -0,0 +1,33 @@
+# vasprintf.m4 serial 2
+dnl Copyright (C) 2002-2003, 2006 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_VASPRINTF],
+[
+  AC_REPLACE_FUNCS(vasprintf)
+  if test $ac_cv_func_vasprintf = no; then
+    AC_LIBOBJ(asprintf)
+    gl_PREREQ_VASPRINTF_H
+    gl_PREREQ_VASPRINTF
+    gl_PREREQ_ASPRINTF
+  fi
+])
+
+# Prerequisites of lib/vasprintf.h.
+AC_DEFUN([gl_PREREQ_VASPRINTF_H],
+[
+  dnl Persuade glibc <stdio.h> to declare asprintf() and vasprintf().
+  AC_REQUIRE([AC_GNU_SOURCE])
+])
+
+# Prerequisites of lib/vasprintf.c.
+AC_DEFUN([gl_PREREQ_VASPRINTF],
+[
+])
+
+# Prerequisites of lib/asprintf.c.
+AC_DEFUN([gl_PREREQ_ASPRINTF],
+[
+])
diff --git a/lgl/vasprintf.c b/lgl/vasprintf.c
new file mode 100644 (file)
index 0000000..18b4edb
--- /dev/null
@@ -0,0 +1,52 @@
+/* Formatted output to strings.
+   Copyright (C) 1999, 2002, 2006 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License along
+   with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+/* Specification.  */
+#include "vasprintf.h"
+
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#include "vasnprintf.h"
+
+/* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW.  */
+#ifndef EOVERFLOW
+# define EOVERFLOW E2BIG
+#endif
+
+int
+vasprintf (char **resultp, const char *format, va_list args)
+{
+  size_t length;
+  char *result = vasnprintf (NULL, &length, format, args);
+  if (result == NULL)
+    return -1;
+
+  if (length > INT_MAX)
+    {
+      free (result);
+      errno = EOVERFLOW;
+      return -1;
+    }
+
+  *resultp = result;
+  /* Return the number of resulting bytes, excluding the trailing NUL.  */
+  return length;
+}
diff --git a/lgl/vasprintf.h b/lgl/vasprintf.h
new file mode 100644 (file)
index 0000000..b7a7ac8
--- /dev/null
@@ -0,0 +1,63 @@
+/* vsprintf with automatic memory allocation.
+   Copyright (C) 2002-2003 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _VASPRINTF_H
+#define _VASPRINTF_H
+
+#if HAVE_VASPRINTF
+
+/* Get asprintf(), vasprintf() declarations.  */
+#include <stdio.h>
+
+#else
+
+/* Get va_list.  */
+#include <stdarg.h>
+
+#ifndef __attribute__
+/* This feature is available in gcc versions 2.5 and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+#  define __attribute__(Spec) /* empty */
+# endif
+/* The __-protected variants of `format' and `printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define __format__ format
+#  define __printf__ printf
+# endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* Write formatted output to a string dynamically allocated with malloc().
+   If the memory allocation succeeds, store the address of the string in
+   *RESULT and return the number of resulting bytes, excluding the trailing
+   NUL.  Upon memory allocation error, or some other error, return -1.  */
+extern int asprintf (char **result, const char *format, ...)
+       __attribute__ ((__format__ (__printf__, 2, 3)));
+extern int vasprintf (char **result, const char *format, va_list args)
+       __attribute__ ((__format__ (__printf__, 2, 0)));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+#endif /* _VASPRINTF_H */