mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
2004-11-03 Timo Schulz <twoaday@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.
This commit is contained in:
parent
b467558d9e
commit
37ecd725e5
2
THANKS
2
THANKS
@ -196,7 +196,7 @@ Thiago Jung Bauermann jungmann@cwb.matrix.com.br
|
||||
Thijmen Klok thijmen@xs4all.nl
|
||||
Thomas Roessler roessler@guug.de
|
||||
Tim Mooney mooney@dogbert.cc.ndsu.nodak.edu
|
||||
Timo Schulz towaday@freakmail.de
|
||||
Timo Schulz twoaday@freakmail.de
|
||||
Todd Vierling tv@pobox.com
|
||||
TOGAWA Satoshi Satoshi.Togawa@jp.yokogawa.com
|
||||
Tom Spindler dogcow@home.merit.edu
|
||||
|
@ -1,3 +1,8 @@
|
||||
2004-11-03 Timo Schulz <twoaday@g10code.com>
|
||||
|
||||
* idea-stub.c (dlopen, dlsym): Use w32_strerror instead of
|
||||
just showing the error number.
|
||||
|
||||
2004-10-14 Werner Koch <wk@g10code.com>
|
||||
|
||||
* rndunix.c (start_gatherer) [ENABLE_SELINUX_HACKS]: Don't allow
|
||||
|
@ -63,7 +63,7 @@ dlopen (const char *pathname, int mode)
|
||||
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 @@ dlclose ( void *handle )
|
||||
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;
|
||||
|
@ -1,3 +1,9 @@
|
||||
2004-11-03 Timo Schulz <twoaday@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@jabberwocky.com>
|
||||
|
||||
* skclist.c (build_sk_list): Don't need to warn about
|
||||
|
@ -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"
|
||||
|
@ -189,19 +189,21 @@ read_passphrase_from_fd( int fd )
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
while (nleft > 0) {
|
||||
if ( !WriteFile( (HANDLE)write_fd, buf, nleft, &nwritten, NULL) ) {
|
||||
log_error("write failed: ec=%d\n", (int)GetLastError());
|
||||
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",
|
||||
/*log_info ("** WriteFile fd=%d nytes=%d nwritten=%d\n",
|
||||
write_fd, nbytes, (int)nwritten);*/
|
||||
Sleep(100);
|
||||
Sleep (100);
|
||||
|
||||
nleft -= nwritten;
|
||||
buf = (const BYTE *)buf + nwritten;
|
||||
@ -212,13 +214,16 @@ writen ( int fd, const void *buf, size_t nbytes )
|
||||
size_t nleft = nbytes;
|
||||
int nwritten;
|
||||
|
||||
while( nleft > 0 ) {
|
||||
nwritten = write( fd, buf, nleft );
|
||||
if( nwritten < 0 ) {
|
||||
if ( errno == EINTR )
|
||||
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) );
|
||||
else
|
||||
{
|
||||
log_error ("write() failed: %s\n", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -232,21 +237,23 @@ writen ( int fd, const void *buf, size_t nbytes )
|
||||
|
||||
|
||||
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;
|
||||
|
||||
while (nleft > 0) {
|
||||
if ( !ReadFile( (HANDLE)read_fd, buf, nleft, &nread, NULL) ) {
|
||||
log_error("read() error: ec=%d\n", (int)GetLastError());
|
||||
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",
|
||||
/*log_info ("** ReadFile fd=%d buflen=%d nread=%d\n",
|
||||
read_fd, buflen, (int)nread);*/
|
||||
Sleep(100);
|
||||
Sleep (100);
|
||||
|
||||
nleft -= nread;
|
||||
buf = (BYTE *)buf + nread;
|
||||
@ -262,22 +269,24 @@ readn ( int fd, void *buf, size_t buflen, size_t *ret_nread )
|
||||
char *p;
|
||||
|
||||
p = buf;
|
||||
while( nleft > 0 ) {
|
||||
nread = read ( fd, buf, nleft );
|
||||
if( nread < 0 ) {
|
||||
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) );
|
||||
log_error ("read() error: %s\n", strerror (errno));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if( !nread )
|
||||
else if (!nread)
|
||||
break; /* EOF */
|
||||
nleft -= nread;
|
||||
buf = (char*)buf + nread;
|
||||
}
|
||||
if( ret_nread )
|
||||
if (ret_nread)
|
||||
*ret_nread = buflen - nleft;
|
||||
#endif
|
||||
|
||||
|
@ -1,3 +1,8 @@
|
||||
2004-11-03 Timo Schulz <twoaday@g10code.com>
|
||||
|
||||
* errors.h: Add w32_strerror prototype.
|
||||
* dynload.h: Use w32_strerror.
|
||||
|
||||
2004-10-27 Werner Koch <wk@g10code.com>
|
||||
|
||||
* dynload.h: Always use it for _WIN32.
|
||||
|
@ -52,9 +52,7 @@ dlsym (void * hd, const char * sym)
|
||||
static __inline__ const char *
|
||||
dlerror (void)
|
||||
{
|
||||
static char buf[32];
|
||||
sprintf (buf, "ec=%lu\n", GetLastError ());
|
||||
return buf;
|
||||
return w32_strerror (0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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*/
|
||||
|
@ -1,3 +1,10 @@
|
||||
2004-11-03 Timo Schulz <twoaday@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@g10code.com>
|
||||
|
||||
* strgutil.c (load_libiconv): Use log_info to avoid failures when
|
||||
|
30
util/iobuf.c
30
util/iobuf.c
@ -287,8 +287,8 @@ fd_cache_open (const char *fname, const char *mode)
|
||||
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 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
||||
|
||||
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 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
||||
|
||||
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 @@ iobuf_get_filelength( IOBUF a )
|
||||
#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 @@ iobuf_seek( IOBUF a, off_t newpos )
|
||||
#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 @@ translate_file_handle ( int fd, int for_write )
|
||||
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;
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ gettext( const char *msgid )
|
||||
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();
|
||||
|
@ -1260,4 +1260,20 @@ asprintf (char **buf, const char *fmt, ...)
|
||||
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*/
|
||||
|
||||
|
||||
|
||||
|
24
util/ttyio.c
24
util/ttyio.c
@ -140,15 +140,15 @@ init_ttyfp(void)
|
||||
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 @@ tty_printf( const char *fmt, ... )
|
||||
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 @@ tty_fprintf (FILE *fp, const char *fmt, ... )
|
||||
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 @@ do_get( const char *prompt, int hidden )
|
||||
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' )
|
||||
|
Loading…
x
Reference in New Issue
Block a user