gnupg (14 files)
cvs user twoaday
cvs at cvs.gnupg.org
Wed Nov 3 20:59:06 CET 2004
Date: Wednesday, November 3, 2004 @ 21:03:46
Author: twoaday
Path: /cvs/gnupg/gnupg
Modified: THANKS cipher/ChangeLog cipher/idea-stub.c g10/ChangeLog
g10/misc.c g10/passphrase.c include/ChangeLog include/dynload.h
include/errors.h util/ChangeLog util/iobuf.c
util/simple-gettext.c util/strgutil.c util/ttyio.c
2004-11-03 Timo Schulz <twoaday at g10code.com>
* strgutil.c (w32_strerror): New.
* ttyio.c (init_ttyfp, tty_printf, do_get): Use it here.
* iobuf.c (fd_cache_open, file_filter): Likewise.
(iobuf_seek, translate_file_handle): Likewise.
-----------------------+
THANKS | 2
cipher/ChangeLog | 5 +
cipher/idea-stub.c | 15 ++---
g10/ChangeLog | 6 ++
g10/misc.c | 4 +
g10/passphrase.c | 135 +++++++++++++++++++++++++-----------------------
include/ChangeLog | 5 +
include/dynload.h | 4 -
include/errors.h | 6 +-
util/ChangeLog | 7 ++
util/iobuf.c | 30 +++++-----
util/simple-gettext.c | 2
util/strgutil.c | 16 +++++
util/ttyio.c | 24 ++++----
14 files changed, 156 insertions(+), 105 deletions(-)
Index: gnupg/THANKS
diff -u gnupg/THANKS:1.75 gnupg/THANKS:1.76
--- gnupg/THANKS:1.75 Wed Oct 13 20:08:39 2004
+++ gnupg/THANKS Wed Nov 3 21:03:46 2004
@@ -196,7 +196,7 @@
Thijmen Klok thijmen at xs4all.nl
Thomas Roessler roessler at guug.de
Tim Mooney mooney at dogbert.cc.ndsu.nodak.edu
-Timo Schulz towaday at freakmail.de
+Timo Schulz twoaday at freakmail.de
Todd Vierling tv at pobox.com
TOGAWA Satoshi Satoshi.Togawa at jp.yokogawa.com
Tom Spindler dogcow at home.merit.edu
Index: gnupg/cipher/ChangeLog
diff -u gnupg/cipher/ChangeLog:1.144 gnupg/cipher/ChangeLog:1.145
--- gnupg/cipher/ChangeLog:1.144 Thu Oct 14 09:21:16 2004
+++ gnupg/cipher/ChangeLog Wed Nov 3 21:03:46 2004
@@ -1,3 +1,8 @@
+2004-11-03 Timo Schulz <twoaday at g10code.com>
+
+ * idea-stub.c (dlopen, dlsym): Use w32_strerror instead of
+ just showing the error number.
+
2004-10-14 Werner Koch <wk at g10code.com>
* rndunix.c (start_gatherer) [ENABLE_SELINUX_HACKS]: Don't allow
Index: gnupg/cipher/idea-stub.c
diff -u gnupg/cipher/idea-stub.c:1.7 gnupg/cipher/idea-stub.c:1.8
--- gnupg/cipher/idea-stub.c:1.7 Tue Oct 12 19:35:50 2004
+++ gnupg/cipher/idea-stub.c Wed Nov 3 21:03:46 2004
@@ -63,7 +63,7 @@
void *h = LoadLibrary (pathname);
if (!h)
{
- log_error ("LoadLibrary failed ec=%d\n", (int)GetLastError());
+ log_error ("LoadLibrary failed: %s\n", w32_strerror (errno));
last_error = 1;
return NULL;
}
@@ -77,25 +77,22 @@
return FreeLibrary (handle);
}
-char*
+
+const char*
dlerror (void)
{
- static char dlerrstr[10];
if (last_error)
- {
- sprintf(dlerrstr, "%d", (int)GetLastError() );
- return dlerrstr;
- }
+ return w32_strerror (0);
return NULL;
}
void*
-dlsym ( void *handle, const char *name )
+dlsym (void *handle, const char *name)
{
void *h = GetProcAddress (handle, name);
if (!h)
{
- log_error ("GetProcAddress failed ec=%d\n", (int)GetLastError());
+ log_error ("GetProcAddress failed: %s\n", w32_strerror (errno));
last_error = 1;
}
return h;
Index: gnupg/g10/ChangeLog
diff -u gnupg/g10/ChangeLog:1.635 gnupg/g10/ChangeLog:1.636
--- gnupg/g10/ChangeLog:1.635 Fri Oct 29 00:09:09 2004
+++ gnupg/g10/ChangeLog Wed Nov 3 21:03:46 2004
@@ -1,3 +1,9 @@
+2004-11-03 Timo Schulz <twoaday at g10code.com>
+
+ * passphrase.c (readn, writen): Use w32_strerror instead
+ of just showing the error number.
+ * misc.c [_WIN32]: Fix warning about missing prototypes.
+
2004-10-28 David Shaw <dshaw at jabberwocky.com>
* skclist.c (build_sk_list): Don't need to warn about
Index: gnupg/g10/misc.c
diff -u gnupg/g10/misc.c:1.61 gnupg/g10/misc.c:1.62
--- gnupg/g10/misc.c:1.61 Thu Oct 14 09:11:56 2004
+++ gnupg/g10/misc.c Wed Nov 3 21:03:46 2004
@@ -37,6 +37,10 @@
#ifdef ENABLE_SELINUX_HACKS
#include <sys/stat.h>
#endif
+#ifdef _WIN32
+#include <time.h>
+#include <process.h>
+#endif
#include "util.h"
#include "main.h"
#include "photoid.h"
Index: gnupg/g10/passphrase.c
diff -u gnupg/g10/passphrase.c:1.67 gnupg/g10/passphrase.c:1.68
--- gnupg/g10/passphrase.c:1.67 Fri Oct 29 00:09:09 2004
+++ gnupg/g10/passphrase.c Wed Nov 3 21:03:46 2004
@@ -189,99 +189,108 @@
}
static int
-writen ( int fd, const void *buf, size_t nbytes )
+writen (int fd, const void *buf, size_t nbytes)
{
#if defined (_WIN32)
- DWORD nwritten, nleft = nbytes;
+ DWORD nwritten, nleft = nbytes;
- while (nleft > 0) {
- if ( !WriteFile( (HANDLE)write_fd, buf, nleft, &nwritten, NULL) ) {
- log_error("write failed: ec=%d\n", (int)GetLastError());
- return -1;
- }
- /*log_info("** WriteFile fd=%d nytes=%d nwritten=%d\n",
- write_fd, nbytes, (int)nwritten);*/
- Sleep(100);
+ while (nleft > 0)
+ {
+ if (!WriteFile ((HANDLE)write_fd, buf, nleft, &nwritten, NULL))
+ {
+ log_error ("write failed: %s\n", w32_strerror (0));
+ return -1;
+ }
+ /*log_info ("** WriteFile fd=%d nytes=%d nwritten=%d\n",
+ write_fd, nbytes, (int)nwritten);*/
+ Sleep (100);
- nleft -= nwritten;
- buf = (const BYTE *)buf + nwritten;
+ nleft -= nwritten;
+ buf = (const BYTE *)buf + nwritten;
}
#elif defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
- /* not implemented */
+ /* not implemented */
#else
- size_t nleft = nbytes;
- int nwritten;
+ size_t nleft = nbytes;
+ int nwritten;
- while( nleft > 0 ) {
- nwritten = write( fd, buf, nleft );
- if( nwritten < 0 ) {
- if ( errno == EINTR )
- nwritten = 0;
- else {
- log_error ( "write() failed: %s\n", strerror (errno) );
- return -1;
+ while (nleft > 0)
+ {
+ nwritten = write (fd, buf, nleft);
+ if (nwritten < 0)
+ {
+ if (errno == EINTR)
+ nwritten = 0;
+ else
+ {
+ log_error ("write() failed: %s\n", strerror (errno));
+ return -1;
}
}
- nleft -= nwritten;
- buf = (const char*)buf + nwritten;
+ nleft -= nwritten;
+ buf = (const char*)buf + nwritten;
}
#endif
- return 0;
+ return 0;
}
static int
-readn ( int fd, void *buf, size_t buflen, size_t *ret_nread )
+readn (int fd, void *buf, size_t buflen, size_t *ret_nread)
{
#if defined (_WIN32)
- DWORD nread, nleft = buflen;
+ DWORD nread, nleft = buflen;
- while (nleft > 0) {
- if ( !ReadFile( (HANDLE)read_fd, buf, nleft, &nread, NULL) ) {
- log_error("read() error: ec=%d\n", (int)GetLastError());
- return -1;
+ while (nleft > 0)
+ {
+ if (!ReadFile ((HANDLE)read_fd, buf, nleft, &nread, NULL))
+ {
+ log_error ("read() error: %s\n", w32_strerror (0));
+ return -1;
}
- if (!nread || GetLastError() == ERROR_BROKEN_PIPE)
- break;
- /*log_info("** ReadFile fd=%d buflen=%d nread=%d\n",
- read_fd, buflen, (int)nread);*/
- Sleep(100);
+ if (!nread || GetLastError() == ERROR_BROKEN_PIPE)
+ break;
+ /*log_info ("** ReadFile fd=%d buflen=%d nread=%d\n",
+ read_fd, buflen, (int)nread);*/
+ Sleep (100);
- nleft -= nread;
- buf = (BYTE *)buf + nread;
+ nleft -= nread;
+ buf = (BYTE *)buf + nread;
}
- if (ret_nread)
- *ret_nread = buflen - nleft;
+ if (ret_nread)
+ *ret_nread = buflen - nleft;
#elif defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__)
- /* not implemented */
+ /* not implemented */
#else
- size_t nleft = buflen;
- int nread;
- char *p;
-
- p = buf;
- while( nleft > 0 ) {
- nread = read ( fd, buf, nleft );
- if( nread < 0 ) {
- if (nread == EINTR)
- nread = 0;
- else {
- log_error ( "read() error: %s\n", strerror (errno) );
- return -1;
- }
+ size_t nleft = buflen;
+ int nread;
+ char *p;
+
+ p = buf;
+ while (nleft > 0)
+ {
+ nread = read (fd, buf, nleft);
+ if (nread < 0)
+ {
+ if (nread == EINTR)
+ nread = 0;
+ else {
+ log_error ("read() error: %s\n", strerror (errno));
+ return -1;
+ }
}
- else if( !nread )
- break; /* EOF */
- nleft -= nread;
- buf = (char*)buf + nread;
+ else if (!nread)
+ break; /* EOF */
+ nleft -= nread;
+ buf = (char*)buf + nread;
}
- if( ret_nread )
- *ret_nread = buflen - nleft;
+ if (ret_nread)
+ *ret_nread = buflen - nleft;
#endif
- return 0;
+ return 0;
}
/* read an entire line */
Index: gnupg/include/ChangeLog
diff -u gnupg/include/ChangeLog:1.78 gnupg/include/ChangeLog:1.79
--- gnupg/include/ChangeLog:1.78 Wed Oct 27 18:32:51 2004
+++ gnupg/include/ChangeLog Wed Nov 3 21:03:46 2004
@@ -1,3 +1,8 @@
+2004-11-03 Timo Schulz <twoaday at g10code.com>
+
+ * errors.h: Add w32_strerror prototype.
+ * dynload.h: Use w32_strerror.
+
2004-10-27 Werner Koch <wk at g10code.com>
* dynload.h: Always use it for _WIN32.
Index: gnupg/include/dynload.h
diff -u gnupg/include/dynload.h:1.4 gnupg/include/dynload.h:1.5
--- gnupg/include/dynload.h:1.4 Wed Oct 27 18:32:51 2004
+++ gnupg/include/dynload.h Wed Nov 3 21:03:46 2004
@@ -52,9 +52,7 @@
static __inline__ const char *
dlerror (void)
{
- static char buf[32];
- sprintf (buf, "ec=%lu\n", GetLastError ());
- return buf;
+ return w32_strerror (0);
}
Index: gnupg/include/errors.h
diff -u gnupg/include/errors.h:1.27 gnupg/include/errors.h:1.28
--- gnupg/include/errors.h:1.27 Thu Sep 9 20:18:33 2004
+++ gnupg/include/errors.h Wed Nov 3 21:03:46 2004
@@ -79,7 +79,11 @@
#define G10ERR_NO_CARD 57
#ifndef HAVE_STRERROR
-char *strerror( int n );
+char *strerror (int n);
+#endif
+
+#ifdef _WIN32
+const char * w32_strerror (int w32_errno);
#endif
#endif /*G10_ERRORS_H*/
Index: gnupg/util/ChangeLog
diff -u gnupg/util/ChangeLog:1.166 gnupg/util/ChangeLog:1.167
--- gnupg/util/ChangeLog:1.166 Wed Nov 3 17:40:29 2004
+++ gnupg/util/ChangeLog Wed Nov 3 21:03:46 2004
@@ -1,3 +1,10 @@
+2004-11-03 Timo Schulz <twoaday at g10code.com>
+
+ * strgutil.c (w32_strerror): New.
+ * ttyio.c (init_ttyfp, tty_printf, do_get): Use it here.
+ * iobuf.c (fd_cache_open, file_filter): Likewise.
+ (iobuf_seek, translate_file_handle): Likewise.
+
2004-11-02 Werner Koch <wk at g10code.com>
* strgutil.c (load_libiconv): Use log_info to avoid failures when
Index: gnupg/util/iobuf.c
diff -u gnupg/util/iobuf.c:1.69 gnupg/util/iobuf.c:1.70
--- gnupg/util/iobuf.c:1.69 Thu Oct 14 09:20:54 2004
+++ gnupg/util/iobuf.c Wed Nov 3 21:03:46 2004
@@ -287,8 +287,8 @@
log_debug ("fd_cache_open (%s) using cached fp\n", fname);
#ifdef HAVE_DOSISH_SYSTEM
if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) {
- log_error ("rewind file failed on handle %p: ec=%d\n",
- fp, (int)GetLastError () );
+ log_error ("rewind file failed on handle %p: %s\n",
+ fp, w32_strerror (errno));
fp = INVALID_FP;
}
#else
@@ -404,9 +404,9 @@
nbytes = 0;
if ( !ReadFile ( f, buf, size, &nread, NULL ) ) {
- int ec = (int)GetLastError ();
- if ( ec != ERROR_BROKEN_PIPE ) {
- log_error("%s: read error: ec=%d\n", a->fname, ec);
+ if ((int)GetLastError () != ERROR_BROKEN_PIPE) {
+ log_error ("%s: read error: %s\n", a->fname,
+ w32_strerror (0));
rc = G10ERR_READ_FILE;
}
}
@@ -452,9 +452,9 @@
nbytes = size;
do {
- if ( size && !WriteFile ( f, p, nbytes, &n, NULL) ) {
- int ec = (int)GetLastError ();
- log_error("%s: write error: ec=%d\n", a->fname, ec);
+ if (size && !WriteFile (f, p, nbytes, &n, NULL)) {
+ log_error ("%s: write error: %s\n", a->fname,
+ w32_strerror (0));
rc = G10ERR_WRITE_FILE;
break;
}
@@ -1835,10 +1835,10 @@
#if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO)
ulong size;
- if ( (size=GetFileSize (fp, NULL)) != 0xffffffff )
+ if ((size=GetFileSize (fp, NULL)) != 0xffffffff)
return size;
- log_error ("GetFileSize for handle %p failed: ec=%d\n",
- fp, (int)GetLastError () );
+ log_error ("GetFileSize for handle %p failed: %s\n",
+ fp, w32_strerror (0));
#else
if( !fstat(my_fileno(fp), &st) )
return st.st_size;
@@ -1945,8 +1945,8 @@
#else
#ifdef HAVE_DOSISH_SYSTEM
if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) {
- log_error ("SetFilePointer failed on handle %p: ec=%d\n",
- b->fp, (int)GetLastError () );
+ log_error ("SetFilePointer failed on handle %p: %s\n",
+ b->fp, w32_strerror (0));
return -1;
}
#else
@@ -2143,8 +2143,8 @@
x = fd;
if (x == -1)
- log_debug ("GetStdHandle(%d) failed: ec=%d\n",
- fd, (int)GetLastError () );
+ log_debug ("GetStdHandle(%d) failed: %s\n",
+ fd, w32_strerror (0));
fd = x;
}
Index: gnupg/util/simple-gettext.c
diff -u gnupg/util/simple-gettext.c:1.11 gnupg/util/simple-gettext.c:1.12
--- gnupg/util/simple-gettext.c:1.11 Sun Oct 31 00:49:09 2004
+++ gnupg/util/simple-gettext.c Wed Nov 3 21:03:46 2004
@@ -427,7 +427,7 @@
log_info("InputCP=%u OutputCP=%u\n", cp1, cp2 );
if( !SetConsoleOutputCP( 1252 ) )
- log_info("SetConsoleOutputCP failed: %d\n", (int)GetLastError() );
+ log_info("SetConsoleOutputCP failed: %s\n", w32_strerror (0));
cp1 = GetConsoleCP();
cp2 = GetConsoleOutputCP();
Index: gnupg/util/strgutil.c
diff -u gnupg/util/strgutil.c:1.44 gnupg/util/strgutil.c:1.45
--- gnupg/util/strgutil.c:1.44 Wed Nov 3 17:40:29 2004
+++ gnupg/util/strgutil.c Wed Nov 3 21:03:46 2004
@@ -1260,4 +1260,20 @@
return status;
}
+const char *
+w32_strerror (int w32_errno)
+{
+ static char strerr[256];
+ int ec = (int)GetLastError ();
+
+ if (w32_errno == 0)
+ w32_errno = ec;
+ FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, w32_errno,
+ MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
+ strerr, DIM (strerr)-1, NULL);
+ return strerr;
+}
#endif /*_WIN32*/
+
+
+
Index: gnupg/util/ttyio.c
diff -u gnupg/util/ttyio.c:1.32 gnupg/util/ttyio.c:1.33
--- gnupg/util/ttyio.c:1.32 Thu Sep 9 19:04:41 2004
+++ gnupg/util/ttyio.c Wed Nov 3 21:03:46 2004
@@ -140,15 +140,15 @@
FILE_SHARE_READ|FILE_SHARE_WRITE,
&sa, OPEN_EXISTING, 0, 0 );
if( con.out == INVALID_HANDLE_VALUE )
- log_fatal("open(CONOUT$) failed: rc=%d", (int)GetLastError() );
+ log_fatal ("open(CONOUT$) failed: %s", w32_strerror (0));
memset(&sa, 0, sizeof(sa));
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
con.in = CreateFileA( "CONIN$", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
&sa, OPEN_EXISTING, 0, 0 );
- if( con.in == INVALID_HANDLE_VALUE )
- log_fatal("open(CONIN$) failed: rc=%d", (int)GetLastError() );
+ if (con.in == INVALID_HANDLE_VALUE)
+ log_fatal ("open(CONIN$) failed: %s", w32_strerror (0));
}
SetConsoleMode(con.in, DEF_INPMODE );
SetConsoleMode(con.out, DEF_OUTMODE );
@@ -212,10 +212,10 @@
if( !buf )
log_bug("vasprintf() failed\n");
- if( !WriteConsoleA( con.out, buf, n, &nwritten, NULL ) )
- log_fatal("WriteConsole failed: rc=%d", (int)GetLastError() );
+ if (!WriteConsoleA (con.out, buf, n, &nwritten, NULL))
+ log_fatal ("WriteConsole failed: %s", w32_strerror (0));
if( n != nwritten )
- log_fatal("WriteConsole failed: %d != %d\n", n, (int)nwritten );
+ log_fatal ("WriteConsole failed: %d != %d\n", n, (int)nwritten );
last_prompt_len += n;
m_free (buf);
}
@@ -259,10 +259,10 @@
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, (int)nwritten );
+ if (!WriteConsoleA (con.out, buf, n, &nwritten, NULL))
+ log_fatal ("WriteConsole failed: %s", w32_strerror (0));
+ if (n != nwritten)
+ log_fatal ("WriteConsole failed: %d != %d\n", n, (int)nwritten);
last_prompt_len += n;
xfree (buf);
}
@@ -387,8 +387,8 @@
for(;;) {
DWORD nread;
- if( !ReadConsoleA( con.in, cbuf, 1, &nread, NULL ) )
- log_fatal("ReadConsole failed: rc=%d", (int)GetLastError() );
+ if (!ReadConsoleA (con.in, cbuf, 1, &nread, NULL))
+ log_fatal ("ReadConsole failed: %s", w32_strerror (0));
if( !nread )
continue;
if( *cbuf == '\n' )
More information about the Gnupg-commits
mailing list