From 19cb96e5d36c15ab116dbc35d3b3edf67ad7a1ff Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 29 Jun 2009 08:54:18 +0000 Subject: [PATCH] The variable is called RET and not RC. --- common/ChangeLog | 9 +++++++++ common/estream.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/common/ChangeLog b/common/ChangeLog index aa04a3d38..475301784 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,7 @@ +2009-06-29 Werner Koch + + * estream.c (es_write_sanitized_utf8_buffer): Typo typo fix. + 2009-06-25 Werner Koch * estream.c (es_write_sanitized_utf8_buffer): Typo fix. @@ -12,6 +16,11 @@ * sexputil.c (get_rsa_pk_from_canon_sexp): Check for error after the loop. Reported by Fabian Keil. +2009-06-22 Werner Koch + + * estream.c (es_pth_read, es_pth_write) [W32]: New. + (ESTREAM_SYS_READ, ESTREAM_SYS_WRITE) [HAVE_PTH]: Use them. + 2009-06-03 Werner Koch * estream.c (es_convert_mode): Rewrite and support the "x" flag. diff --git a/common/estream.c b/common/estream.c index 255070b58..1b9617fe5 100644 --- a/common/estream.c +++ b/common/estream.c @@ -138,8 +138,8 @@ dummy_mutex_call_int (estream_mutex_t mutex) /* Primitive system I/O. */ #ifdef HAVE_PTH -# define ESTREAM_SYS_READ pth_read -# define ESTREAM_SYS_WRITE pth_write +# define ESTREAM_SYS_READ es_pth_read +# define ESTREAM_SYS_WRITE es_pth_write #else # define ESTREAM_SYS_READ read # define ESTREAM_SYS_WRITE write @@ -231,7 +231,7 @@ static estream_mutex_t estream_list_lock; while (0) -/* Malloc wrappers to overcvome problems on some older OSes. */ +/* Malloc wrappers to overcome problems on some older OSes. */ static void * mem_alloc (size_t n) { @@ -325,6 +325,45 @@ es_list_iterate (estream_iterator_t iterator) return ret; } + + +/* + * I/O Helper + * + * Unfortunately our Pth emulation for Windows expects system handles + * for pth_read and pth_write. We use a simple approach to fix this: + * If the function returns an error we fall back to a vanilla read or + * write, assuming that we do I/O on a plain file where the operation + * can't block. + */ +#ifdef HAVE_PTH +static int +es_pth_read (int fd, void *buffer, size_t size) +{ +# ifdef HAVE_W32_SYSTEM + int rc = pth_read (fd, buffer, size); + if (rc == -1 && errno == EINVAL) + rc = read (fd, buffer, size); + return rc; +# else /*!HAVE_W32_SYSTEM*/ + return pth_read (fd, buffer, size); +# endif /* !HAVE_W32_SYSTEM*/ +} + +static int +es_pth_write (int fd, const void *buffer, size_t size) +{ +# ifdef HAVE_W32_SYSTEM + int rc = pth_write (fd, buffer, size); + if (rc == -1 && errno == EINVAL) + rc = write (fd, buffer, size); + return rc; +# else /*!HAVE_W32_SYSTEM*/ + return pth_write (fd, buffer, size); +# endif /* !HAVE_W32_SYSTEM*/ +} +#endif /*HAVE_PTH*/ + /* @@ -3205,7 +3244,7 @@ es_write_sanitized_utf8_buffer (estream_t stream, *bytes_written = strlen (buf); ret = es_fputs (buf, stream); xfree (buf); - return rc == EOF? ret : (int)i; + return ret == EOF? ret : (int)i; } else return es_write_sanitized (stream, p, length, delimiters, bytes_written);