diff options
author | Marcus Brinkmann <[email protected]> | 2009-10-08 12:48:21 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2009-10-08 12:48:21 +0000 |
commit | 6e96c1d46ec6598d49a3812c560e8a14b4a28dd9 (patch) | |
tree | 21442e7d699fb9844bbe08f9d92d65817ecedb3f | |
parent | Comment fix. (diff) | |
download | libassuan-6e96c1d46ec6598d49a3812c560e8a14b4a28dd9.tar.gz libassuan-6e96c1d46ec6598d49a3812c560e8a14b4a28dd9.zip |
2009-10-08 Marcus Brinkmann <[email protected]>
* configure.ac: AC_REPLACE_FUNCS for vasprintf.
src/
2009-10-08 Marcus Brinkmann <[email protected]>
* 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.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | src/ChangeLog | 14 | ||||
-rw-r--r-- | src/assuan-defs.h | 3 | ||||
-rw-r--r-- | src/assuan-pipe-connect.c | 24 | ||||
-rw-r--r-- | src/assuan.h | 10 | ||||
-rw-r--r-- | src/libassuan.def | 116 | ||||
-rw-r--r-- | src/libassuan.vers | 2 | ||||
-rw-r--r-- | src/vasprintf.c | 192 |
9 files changed, 281 insertions, 85 deletions
@@ -1,3 +1,7 @@ +2009-10-08 Marcus Brinkmann <[email protected]> + + * configure.ac: AC_REPLACE_FUNCS for vasprintf. + 2009-09-19 Marcus Brinkmann <[email protected]> * tests/fdpassing.c: Update to new API. diff --git a/configure.ac b/configure.ac index 4bc5f85..dce02ad 100644 --- a/configure.ac +++ b/configure.ac @@ -308,6 +308,7 @@ AC_REPLACE_FUNCS(stpcpy) # Check for unistd.h for setenv replacement function. AC_CHECK_HEADERS(unistd.h) AC_REPLACE_FUNCS(setenv) +AC_REPLACE_FUNCS(vasprintf) # diff --git a/src/ChangeLog b/src/ChangeLog index 55cc12f..f2ae1e6 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,17 @@ +2009-10-08 Marcus Brinkmann <[email protected]> + + * 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 <[email protected]> * assuan.h: Comment fix. diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 1d6acee..c20cef5 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -276,8 +276,7 @@ int _assuan_error_is_eagain (gpg_error_t err); 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*/ diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c index 15b5232..c5e20e7 100644 --- a/src/assuan-pipe-connect.c +++ b/src/assuan-pipe-connect.c @@ -541,7 +541,7 @@ socketpair_connect (assuan_context_t ctx, /* 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 @@ build_w32_commandline (const char * const *argv, char **cmdline) } n++; - buf = p = _assuan_malloc (n); + buf = p = _assuan_malloc (ctx, n); if (!buf) return -1; @@ -606,7 +606,7 @@ create_inheritable_pipe (assuan_context_t ctx, 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 @@ create_inheritable_pipe (assuan_context_t ctx, 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 @@ pipe_connect_w32 (assuan_context_t ctx, 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 @@ pipe_connect_w32 (assuan_context_t ctx, { 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 @@ pipe_connect_w32 (assuan_context_t ctx, 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 @@ pipe_connect_w32 (assuan_context_t ctx, )) { 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) { diff --git a/src/assuan.h b/src/assuan.h index 9a72d5b..20de1b0 100644 --- a/src/assuan.h +++ b/src/assuan.h @@ -246,16 +246,6 @@ void assuan_set_io_monitor (assuan_context_t ctx, /* 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 diff --git a/src/libassuan.def b/src/libassuan.def index 59fe38c..cc5509e 100644 --- a/src/libassuan.def +++ b/src/libassuan.def @@ -27,65 +27,63 @@ EXPORTS 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 diff --git a/src/libassuan.vers b/src/libassuan.vers index 14c0cc7..61eaebd 100644 --- a/src/libassuan.vers +++ b/src/libassuan.vers @@ -30,7 +30,6 @@ LIBASSUAN_1.0 { 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 @@ LIBASSUAN_1.0 { 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; diff --git a/src/vasprintf.c b/src/vasprintf.c new file mode 100644 index 0000000..77113a3 --- /dev/null +++ b/src/vasprintf.c @@ -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 */ |