[svn] assuan - r306 - in trunk: . src

svn author marcus cvs at cvs.gnupg.org
Thu Oct 8 14:48:21 CEST 2009


Author: marcus
Date: 2009-10-08 14:48:21 +0200 (Thu, 08 Oct 2009)
New Revision: 306

Added:
   trunk/src/vasprintf.c
Modified:
   trunk/ChangeLog
   trunk/configure.ac
   trunk/src/ChangeLog
   trunk/src/assuan-defs.h
   trunk/src/assuan-pipe-connect.c
   trunk/src/assuan.h
   trunk/src/libassuan.def
   trunk/src/libassuan.vers
Log:
2009-10-08  Marcus Brinkmann  <marcus at g10code.de>

	* configure.ac: AC_REPLACE_FUNCS for vasprintf.

src/
2009-10-08  Marcus Brinkmann  <marcus at g10code.de>

	* assuan.h (assuan_get_assuan_log_stream,
	assuan_set_assuan_log_stream): Remove prototypes.
	* libassuan.def: Remove assuan_get_assuan_log_stream,
	assuan_set_assuan_log_stream.
	* libassuan.vers: Likewise.
	* assuan-defs.h (_assuan_w32_strerror): Fix prototype.
	(w32_strerror): Remove macro.
	* assuan-pipe-connect.c (build_w32_commandline): Add argument for
	context.  Use it for malloc routines.  Use _assuan_w32_strerror
	instead of w32_strerror.
	* vasprintf.c: New file.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/ChangeLog	2009-10-08 12:48:21 UTC (rev 306)
@@ -1,3 +1,7 @@
+2009-10-08  Marcus Brinkmann  <marcus at g10code.de>
+
+	* configure.ac: AC_REPLACE_FUNCS for vasprintf.
+
 2009-09-19  Marcus Brinkmann  <marcus at g10code.de>
 
 	* tests/fdpassing.c: Update to new API.

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/ChangeLog	2009-10-08 12:48:21 UTC (rev 306)
@@ -1,3 +1,17 @@
+2009-10-08  Marcus Brinkmann  <marcus at g10code.de>
+
+	* assuan.h (assuan_get_assuan_log_stream,
+	assuan_set_assuan_log_stream): Remove prototypes.
+	* libassuan.def: Remove assuan_get_assuan_log_stream,
+	assuan_set_assuan_log_stream.
+	* libassuan.vers: Likewise.
+	* assuan-defs.h (_assuan_w32_strerror): Fix prototype.
+	(w32_strerror): Remove macro.
+	* assuan-pipe-connect.c (build_w32_commandline): Add argument for
+	context.  Use it for malloc routines.  Use _assuan_w32_strerror
+	instead of w32_strerror.
+	* vasprintf.c: New file.
+
 2009-09-29  Werner Koch  <wk at g10code.com>
 
 	* assuan.h: Comment fix.

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/configure.ac	2009-10-08 12:48:21 UTC (rev 306)
@@ -308,6 +308,7 @@
 # Check for unistd.h for setenv replacement function.
 AC_CHECK_HEADERS(unistd.h)
 AC_REPLACE_FUNCS(setenv)
+AC_REPLACE_FUNCS(vasprintf)
 
 
 #

Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/assuan-defs.h	2009-10-08 12:48:21 UTC (rev 306)
@@ -276,8 +276,7 @@
   assuan_set_error ((c), _assuan_error (c,e), (t))
 
 #ifdef HAVE_W32_SYSTEM
-const char *_assuan_w32_strerror (int ec);
-#define w32_strerror(e) _assuan_w32_strerror ((e))
+char *_assuan_w32_strerror (assuan_context_t ctx, int ec);
 #endif /*HAVE_W32_SYSTEM*/
 
 

Modified: trunk/src/assuan-pipe-connect.c
===================================================================
--- trunk/src/assuan-pipe-connect.c	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/assuan-pipe-connect.c	2009-10-08 12:48:21 UTC (rev 306)
@@ -541,7 +541,7 @@
 /* Build a command line for use with W32's CreateProcess.  On success
    CMDLINE gets the address of a newly allocated string.  */
 static int
-build_w32_commandline (const char * const *argv, char **cmdline)
+build_w32_commandline (assuan_context_t ctx, const char * const *argv, char **cmdline)
 {
   int i, n;
   const char *s;
@@ -558,7 +558,7 @@
     }
   n++;
 
-  buf = p = _assuan_malloc (n);
+  buf = p = _assuan_malloc (ctx, n);
   if (!buf)
     return -1;
 
@@ -606,7 +606,7 @@
   if (!CreatePipe (&r, &w, &sec_attr, 0))
     {
       TRACE1 (ctx, ASSUAN_LOG_SYSIO, "create_inheritable_pipe", ctx,
-	      "CreatePipe failed: %s", w32_strerror (ctx, -1));
+	      "CreatePipe failed: %s", _assuan_w32_strerror (ctx, -1));
       return -1;
     }
 
@@ -615,7 +615,7 @@
                         TRUE, DUPLICATE_SAME_ACCESS ))
     {
       TRACE1 (ctx, ASSUAN_LOG_SYSIO, "create_inheritable_pipe", ctx,
-	      "DuplicateHandle failed: %s", w32_strerror (ctx, -1));
+	      "DuplicateHandle failed: %s", _assuan_w32_strerror (ctx, -1));
       CloseHandle (r);
       CloseHandle (w);
       return -1;
@@ -675,13 +675,13 @@
   sprintf (mypidstr, "%lu", (unsigned long)getpid ());
 
   /* Build the command line.  */
-  if (build_w32_commandline (argv, &cmdline))
+  if (build_w32_commandline (ctx, argv, &cmdline))
     return _assuan_error (ctx, gpg_err_code_from_syserror ());
 
   /* Create thew two pipes. */
   if (create_inheritable_pipe (ctx, rp, 0))
     {
-      _assuan_free (cmdline);
+      _assuan_free (ctx, cmdline);
       return _assuan_error (ctx, GPG_ERR_ASS_GENERAL);
     }
   
@@ -689,7 +689,7 @@
     {
       CloseHandle (rp[0]);
       CloseHandle (rp[1]);
-      _assuan_free (cmdline);
+      _assuan_free (ctx, cmdline);
       return _assuan_error (ctx, GPG_ERR_ASS_GENERAL);
     }
 
@@ -729,12 +729,12 @@
       if (nullfd == INVALID_HANDLE_VALUE)
         {
 	  TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_w32", ctx,
-		  "can't open `nul': %s", w32_strerror (ctx, -1));
+		  "can't open `nul': %s", _assuan_w32_strerror (ctx, -1));
           CloseHandle (rp[0]);
           CloseHandle (rp[1]);
           CloseHandle (wp[0]);
           CloseHandle (wp[1]);
-          _assuan_free (cmdline);
+          _assuan_free (ctx, cmdline);
 	  /* FIXME: Cleanup?  */
           return -1;
         }
@@ -765,18 +765,18 @@
                       ))
     {
       TRACE1 (ctx, ASSUAN_LOG_SYSIO, "pipe_connect_w32", ctx,
-	      "CreateProcess failed: %s", w32_strerror (ctx, -1));
+	      "CreateProcess failed: %s", _assuan_w32_strerror (ctx, -1));
       CloseHandle (rp[0]);
       CloseHandle (rp[1]);
       CloseHandle (wp[0]);
       CloseHandle (wp[1]);
       if (nullfd != INVALID_HANDLE_VALUE)
         CloseHandle (nullfd);
-      _assuan_free (cmdline);
+      _assuan_free (ctx, cmdline);
       /* FIXME: Cleanup?  */
       return _assuan_error (ctx, GPG_ERR_ASS_GENERAL);
     }
-  _assuan_free (cmdline);
+  _assuan_free (ctx, cmdline);
   cmdline = NULL;
   if (nullfd != INVALID_HANDLE_VALUE)
     {

Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/assuan.h	2009-10-08 12:48:21 UTC (rev 306)
@@ -246,16 +246,6 @@
 
 /* Configuration of the default log handler.  */
 
-/* Set the stream to which assuan should log message not associated
-   with a context.  By default, this is stderr.  The default value
-   will be changed when the first log stream is associated with a
-   context.  Note, that this function is not thread-safe and should
-   in general be used right at startup. */
-extern void assuan_set_assuan_log_stream (FILE *fp);
-
-/* Return the stream which is currently being using for global logging.  */
-extern FILE *assuan_get_assuan_log_stream (void);
-
 /* Set the prefix to be used at the start of a line emitted by assuan
    on the log stream.  The default is the empty string.  Note, that
    this function is not thread-safe and should in general be used

Modified: trunk/src/libassuan.def
===================================================================
--- trunk/src/libassuan.def	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/libassuan.def	2009-10-08 12:48:21 UTC (rev 306)
@@ -27,65 +27,63 @@
     assuan_end_confidential		@6
     assuan_get_active_fds		@7
     assuan_get_assuan_log_prefix	@8
-    assuan_get_assuan_log_stream	@9
-    assuan_get_data_fp			@10  
-    assuan_get_flag			@11  
-    assuan_get_gpg_err_source           @12
-    assuan_get_input_fd			@13  
-    assuan_get_log_cb                   @14
-    assuan_get_malloc_hooks             @15
-    assuan_get_output_fd		@16  
-    assuan_get_pid			@17
-    assuan_get_pointer			@18
-    assuan_init_pipe_server		@19
-    assuan_init_socket_server		@20  
-    assuan_init_socket_server_ext	@21
-    assuan_inquire			@22
-    assuan_inquire_ext			@23
-    assuan_new                          @24
-    assuan_new_ext                      @25
-    assuan_pending_line			@26
-    assuan_pipe_connect			@27
-    assuan_pipe_connect_ext		@28
-    assuan_process			@29
-    assuan_process_done			@30
-    assuan_process_next			@31
-    assuan_read_line			@32
-    assuan_receivefd			@33
-    assuan_register_bye_notify		@34
-    assuan_register_cancel_notify	@35
-    assuan_register_command		@36
-    assuan_register_input_notify	@37
-    assuan_register_option_handler	@38
-    assuan_register_output_notify	@39
-    assuan_register_post_cmd_notify	@40
-    assuan_register_reset_notify	@41
-    assuan_release                      @42
-    assuan_send_data			@43
-    assuan_sendfd			@44
-    assuan_set_assuan_log_prefix	@45
-    assuan_set_assuan_log_stream	@46
-    assuan_set_error			@47
-    assuan_set_flag			@48
-    assuan_set_gpg_err_source           @49
-    assuan_set_hello_line		@50
-    assuan_set_io_monitor		@51
-    assuan_set_log_cb                   @52
-    assuan_set_log_stream		@53
-    assuan_set_malloc_hooks		@54
-    assuan_set_okay_line		@55
-    assuan_set_pointer			@56
-    assuan_sock_bind			@57
-    assuan_sock_check_nonce		@58
-    assuan_sock_close			@59
-    assuan_sock_connect			@60
-    assuan_sock_get_nonce		@61
-    assuan_sock_new			@62
-    assuan_socket_connect		@63
-    assuan_socket_connect_ext		@64
-    assuan_transact			@65
-    assuan_write_line			@66
-    assuan_write_status			@67
+    assuan_get_data_fp			@9
+    assuan_get_flag			@10  
+    assuan_get_gpg_err_source           @11
+    assuan_get_input_fd			@12  
+    assuan_get_log_cb                   @13
+    assuan_get_malloc_hooks             @14
+    assuan_get_output_fd		@15  
+    assuan_get_pid			@16
+    assuan_get_pointer			@17
+    assuan_init_pipe_server		@18
+    assuan_init_socket_server		@19  
+    assuan_init_socket_server_ext	@20
+    assuan_inquire			@21
+    assuan_inquire_ext			@22
+    assuan_new                          @23
+    assuan_new_ext                      @24
+    assuan_pending_line			@25
+    assuan_pipe_connect			@26
+    assuan_pipe_connect_ext		@27
+    assuan_process			@28
+    assuan_process_done			@29
+    assuan_process_next			@30
+    assuan_read_line			@31
+    assuan_receivefd			@32
+    assuan_register_bye_notify		@33
+    assuan_register_cancel_notify	@34
+    assuan_register_command		@35
+    assuan_register_input_notify	@36
+    assuan_register_option_handler	@37
+    assuan_register_output_notify	@38
+    assuan_register_post_cmd_notify	@39
+    assuan_register_reset_notify	@40
+    assuan_release                      @41
+    assuan_send_data			@42
+    assuan_sendfd			@43
+    assuan_set_assuan_log_prefix	@44
+    assuan_set_error			@45
+    assuan_set_flag			@46
+    assuan_set_gpg_err_source           @47
+    assuan_set_hello_line		@48
+    assuan_set_io_monitor		@49
+    assuan_set_log_cb                   @50
+    assuan_set_log_stream		@51
+    assuan_set_malloc_hooks		@52
+    assuan_set_okay_line		@53
+    assuan_set_pointer			@54
+    assuan_sock_bind			@55
+    assuan_sock_check_nonce		@56
+    assuan_sock_close			@57
+    assuan_sock_connect			@58
+    assuan_sock_get_nonce		@59
+    assuan_sock_new			@60
+    assuan_socket_connect		@61
+    assuan_socket_connect_ext		@62
+    assuan_transact			@63
+    assuan_write_line			@64
+    assuan_write_status			@65
 
 ; END
 

Modified: trunk/src/libassuan.vers
===================================================================
--- trunk/src/libassuan.vers	2009-09-29 19:13:26 UTC (rev 305)
+++ trunk/src/libassuan.vers	2009-10-08 12:48:21 UTC (rev 306)
@@ -30,7 +30,6 @@
     assuan_end_confidential;
     assuan_get_active_fds;
     assuan_get_assuan_log_prefix;
-    assuan_get_assuan_log_stream;
     assuan_get_data_fp;
     assuan_get_flag;
     assuan_get_input_fd;
@@ -62,7 +61,6 @@
     assuan_send_data;
     assuan_sendfd;
     assuan_set_assuan_log_prefix;
-    assuan_set_assuan_log_stream;
     assuan_set_error;
     assuan_set_flag;
     assuan_set_hello_line;

Added: trunk/src/vasprintf.c
===================================================================
--- trunk/src/vasprintf.c	                        (rev 0)
+++ trunk/src/vasprintf.c	2009-10-08 12:48:21 UTC (rev 306)
@@ -0,0 +1,192 @@
+/* Like vsprintf but provides a pointer to malloc'd storage, which must
+   be freed by the caller.
+   Copyright (C) 1994, 2002 Free Software Foundation, Inc.
+
+This file is part of the libiberty library.
+Libiberty is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+Libiberty 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
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with libiberty; see the file COPYING.LIB.  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
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdarg.h>
+
+
+#ifndef va_copy /* According to POSIX, va_copy is a macro. */
+#if defined (__GNUC__) && defined (__PPC__) \
+     && (defined (_CALL_SYSV) || defined (_WIN32))
+#define va_copy(d, s) (*(d) = *(s))
+#elif defined (MUST_COPY_VA_BYVAL)
+#define va_copy(d, s) ((d) = (s))
+#else 
+#define va_copy(d, s) memcpy ((d), (s), sizeof (va_list))
+#endif 
+#endif 
+
+
+#ifdef TEST
+int global_total_width;
+#endif
+
+static int int_vasprintf (char **, const char *, va_list *);
+
+static int
+int_vasprintf (result, format, args)
+     char **result;
+     const char *format;
+     va_list *args;
+{
+  const char *p = format;
+  /* Add one to make sure that it is never zero, which might cause malloc
+     to return NULL.  */
+  int total_width = strlen (format) + 1;
+  va_list ap;
+
+  va_copy (ap, *args);
+
+  while (*p != '\0')
+    {
+      if (*p++ == '%')
+	{
+	  while (strchr ("-+ #0", *p))
+	    ++p;
+	  if (*p == '*')
+	    {
+	      ++p;
+	      total_width += abs (va_arg (ap, int));
+	    }
+	  else
+	    total_width += strtoul (p, (char **) &p, 10);
+	  if (*p == '.')
+	    {
+	      ++p;
+	      if (*p == '*')
+		{
+		  ++p;
+		  total_width += abs (va_arg (ap, int));
+		}
+	      else
+	      total_width += strtoul (p, (char **) &p, 10);
+	    }
+	  while (strchr ("hlL", *p))
+	    ++p;
+	  /* Should be big enough for any format specifier except %s and floats.  */
+	  total_width += 30;
+	  switch (*p)
+	    {
+	    case 'd':
+	    case 'i':
+	    case 'o':
+	    case 'u':
+	    case 'x':
+	    case 'X':
+	    case 'c':
+	      (void) va_arg (ap, int);
+	      break;
+	    case 'f':
+	    case 'e':
+	    case 'E':
+	    case 'g':
+	    case 'G':
+	      (void) va_arg (ap, double);
+	      /* Since an ieee double can have an exponent of 307, we'll
+		 make the buffer wide enough to cover the gross case. */
+	      total_width += 307;
+	      break;
+	    case 's':
+              {
+                char *tmp = va_arg (ap, char *);
+                if (tmp)
+                  total_width += strlen (tmp);
+                else /* in case the vsprintf does prints a text */
+                  total_width += 25; /* e.g. "(null pointer reference)" */
+              }
+	      break;
+	    case 'p':
+	    case 'n':
+	      (void) va_arg (ap, char *);
+	      break;
+	    }
+	  p++;
+	}
+    }
+#ifdef TEST
+  global_total_width = total_width;
+#endif
+  *result = malloc (total_width);
+  if (*result != NULL)
+    return vsprintf (*result, format, *args);
+  else
+    return 0;
+}
+
+int
+vasprintf (result, format, args)
+     char **result;
+     const char *format;
+#if defined (_BSD_VA_LIST_) && defined (__FreeBSD__)
+     _BSD_VA_LIST_ args;
+#else
+     va_list args;
+#endif
+{
+  return int_vasprintf (result, format, &args);
+}
+
+
+int
+asprintf (char **buf, const char *fmt, ...)
+{
+  int status;
+  va_list ap;
+
+  va_start (ap, fmt);
+  status = vasprintf (buf, fmt, ap);
+  va_end (ap);
+  return status;
+}
+
+
+#ifdef TEST
+void
+checkit (const char* format, ...)
+{
+  va_list args;
+  char *result;
+
+  va_start (args, format);
+  vasprintf (&result, format, args);
+  if (strlen (result) < global_total_width)
+    printf ("PASS: ");
+  else
+    printf ("FAIL: ");
+  printf ("%d %s\n", global_total_width, result);
+}
+
+int
+main (void)
+{
+  checkit ("%d", 0x12345678);
+  checkit ("%200d", 5);
+  checkit ("%.300d", 6);
+  checkit ("%100.150d", 7);
+  checkit ("%s", "jjjjjjjjjiiiiiiiiiiiiiiioooooooooooooooooppppppppppppaa\n\
+777777777777777777333333333333366666666666622222222222777777777777733333");
+  checkit ("%f%s%d%s", 1.0, "foo", 77, "asdjffffffffffffffiiiiiiiiiiixxxxx");
+}
+#endif /* TEST */




More information about the Gnupg-commits mailing list