diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/ChangeLog | 10 | ||||
-rw-r--r-- | util/dotlock.c | 4 | ||||
-rw-r--r-- | util/strgutil.c | 99 | ||||
-rw-r--r-- | util/ttyio.c | 36 |
4 files changed, 119 insertions, 30 deletions
diff --git a/util/ChangeLog b/util/ChangeLog index e9d8da7b7..a8854f618 100644 --- a/util/ChangeLog +++ b/util/ChangeLog @@ -1,3 +1,13 @@ +2001-06-06 Werner Koch <[email protected]> + + * strgutil.c (vasprintf) [__MINGW32__]: New. Taken from libiberty. + * ttyio.c (tty_printf) [__MINGW32__]: Replaced the sprintf with + the new vasprintf. + +2001-06-05 Werner Koch <[email protected]> + + * dotlock.c (make_dotlock): Typo fixes. + 2001-05-25 Werner Koch <[email protected]> * ttyio.c (do_get): Fixed a serious format string bug. Thanks to diff --git a/util/dotlock.c b/util/dotlock.c index 21385a707..6b65e62b2 100644 --- a/util/dotlock.c +++ b/util/dotlock.c @@ -237,7 +237,7 @@ make_dotlock( DOTLOCK h, long timeout ) continue; } else if( pid == getpid() ) { - log_info( "Oops: lock already hold by us\n"); + log_info( "Oops: lock already held by us\n"); h->locked = 1; return 0; /* okay */ } @@ -250,7 +250,7 @@ make_dotlock( DOTLOCK h, long timeout ) } if( timeout == -1 ) { struct timeval tv; - log_info( "waiting for lock (hold by %d%s) %s...\n", + log_info( "waiting for lock (held by %d%s) %s...\n", pid, maybe_dead, maybe_deadlock(h)? "(deadlock?) ":""); diff --git a/util/strgutil.c b/util/strgutil.c index aba340aff..9a8cffe9e 100644 --- a/util/strgutil.c +++ b/util/strgutil.c @@ -1,5 +1,5 @@ /* strgutil.c - string utilities - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Copyright (C) 1994, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. * * This file is part of GnuPG. * @@ -638,3 +638,100 @@ memicmp( const char *a, const char *b, size_t n ) #endif +#ifdef __MINGW32__ +/* + * Like vsprintf but provides a pointer to malloc'd storage, which + * must be freed by the caller (m_free). Taken from libiberty as + * found in gcc-2.95.2 and a little bit modernized. + * FIXME: Write a new CRT for W32. + */ +int +vasprintf ( 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; + + /* this is not really portable but works under Windows */ + memcpy ( &ap, &args, sizeof (va_list)); + + while (*p != '\0') + { + if (*p++ == '%') + { + while (strchr ("-+ #0", *p)) + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + { + char *endp; + total_width += strtoul (p, &endp, 10); + p = endp; + } + if (*p == '.') + { + ++p; + if (*p == '*') + { + ++p; + total_width += abs (va_arg (ap, int)); + } + else + { + char *endp; + total_width += strtoul (p, &endp, 10); + p = endp; + } + } + 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; + + case 's': + total_width += strlen (va_arg (ap, char *)); + break; + case 'p': + case 'n': + (void) va_arg (ap, char *); + break; + } + } + } + *result = m_alloc (total_width); + if (*result != NULL) + return vsprintf (*result, format, args); + else + return 0; +} + +#endif /*__MINGW32__*/ + + diff --git a/util/ttyio.c b/util/ttyio.c index a343060d7..3106b5ae5 100644 --- a/util/ttyio.c +++ b/util/ttyio.c @@ -166,39 +166,21 @@ tty_printf( const char *fmt, ... ) va_start( arg_ptr, fmt ) ; #ifdef __MINGW32__ - { static char *buf; - static size_t bufsize; - int n; + { + char *buf = NULL; + int n; DWORD nwritten; - #if 0 /* the dox say, that there is a snprintf, but I didn't found - * it, so we use a static buffer for now */ - do { - if( n == -1 || !buf ) { - m_free(buf); - bufsize += 200; - /* better check the new size; (we use M$ functions) */ - if( bufsize > 50000 ) - log_bug("vsnprintf probably failed\n"); - buf = m_alloc( bufsize ); - } - n = _vsnprintf(buf, bufsize-1, fmt, arg_ptr); - } while( n == -1 ); - #else - if( !buf ) { - bufsize += 1000; - buf = m_alloc( bufsize ); - } - n = vsprintf(buf, fmt, arg_ptr); - if( n == -1 ) - log_bug("vsprintf() failed\n"); - #endif - + n = vasprintf(&buf, fmt, arg_ptr); + if( !buf ) + log_bug("vasprintf() failed\n"); + if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) ) log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() ); if( n != nwritten ) - log_fatal("WriteConsole failed: %d != %d\n", n, nwritten ); + log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten ); last_prompt_len += n; + m_free (buf); } #else last_prompt_len += vfprintf(ttyfp,fmt,arg_ptr) ; |