[svn] GnuPG - r5275 - in trunk: . common

svn author wk cvs at cvs.gnupg.org
Tue Mar 2 22:25:08 CET 2010


Author: wk
Date: 2010-03-02 22:25:08 +0100 (Tue, 02 Mar 2010)
New Revision: 5275

Modified:
   trunk/common/ChangeLog
   trunk/common/convert.c
   trunk/common/estream-printf.c
   trunk/common/estream-printf.h
   trunk/common/estream.c
   trunk/common/estream.h
   trunk/common/gettime.c
   trunk/common/homedir.c
   trunk/common/http.c
   trunk/common/i18n.c
   trunk/common/iobuf.c
   trunk/common/membuf.c
   trunk/common/signal.c
   trunk/common/sysutils.c
   trunk/common/util.h
   trunk/common/xreadline.c
   trunk/configure.ac
Log:
First steps towards the W32CE port


Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/ChangeLog	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,3 +1,33 @@
+2010-03-02  Werner Koch  <wk at g10code.com>
+
+	* estream.c, estream.h, estream-printf.c, estream-printf.h: Update
+	from libestream.
+
+2010-03-01  Werner Koch  <wk at g10code.com>
+
+	* signal.c [!HAVE_SIGNAL_H]: Don't include signal.h.
+
+	* iobuf.c (direct_open) [W32CE]: Make filename to wchar_t.
+	(iobuf_cancel) [W32CE]: Use DeleteFile.
+
+	* gettime.c (dump_isotime): Use "%s" to print "none".
+
+	* homedir.c (standard_homedir) [W32CE]: Use wchar_t to create the
+	directory.
+	(w32_rootdir) [W32CE]: Likewise.
+
+	* sysutils.c (translate_sys2libc_fd) [W32CE]: Add support.
+	(gnupg_tmpfile) [W32CE]: Ditto.
+	(_gnupg_getenv) [W32CE]: New.
+
+	* util.h (getpid, getenv) [W32CE]: New.
+
+	* i18n.c (i18n_switchto_utf8)
+	(i18n_switchback) [USE_SIMPLE_GETTEXT]: Use new function from
+	libgpg-error which supports proper restoring.
+
+	* sysutils.c (get_session_marker): Simplified by using gcrypt.
+
 2009-12-08  Marcus Brinkmann  <marcus at g10code.de>
 
 	* Makefile.am (audit-events.h, status.h) [!MAINTAINER_MODE]: No
@@ -266,7 +296,7 @@
 
 	* percent.c, t-percent.c: New.
 
-	* exechelp.c (gnupg_spawn_process, gnupg_spawn_process_fd) 
+	* exechelp.c (gnupg_spawn_process, gnupg_spawn_process_fd)
 	(gnupg_spawn_process_detached) [W32]: Remove debug output.
 
 2008-11-20  Werner Koch  <wk at g10code.com>
@@ -481,7 +511,7 @@
 
 2007-11-05  Werner Koch  <wk at g10code.com>
 
-	* audit.c, audit.h: New. 
+	* audit.c, audit.h: New.
 	* Makefile.am: Add rules to build audit-events.h.
 	* exaudit.awk: New.
 	* mkstrtable.awk: New.  Taken from libgpg-error.
@@ -506,7 +536,7 @@
 	(gnupg_create_inbound_pipe): New.
 	* util.h (GNUPG_MODULE_NAME_GPGSM, GNUPG_MODULE_NAME_GPG): New.
 	* homedir.c (gnupg_module_name): Add them
-	
+
 2007-08-28  Werner Koch  <wk at g10code.com>
 
 	* gettime.c (check_isotime, add_isotime): New.  Originally written
@@ -527,7 +557,7 @@
 2007-08-22  Werner Koch  <wk at g10code.com>
 
 	Updated estream from libestream.
-	
+
 	* estream.c (mem_malloc, mem_realloc, mem_free): New.  Use them
 	instead of the ES_MEM_foo.
 	* estream.c (estream_cookie_mem): Remove members DONT_FREE,
@@ -596,7 +626,7 @@
 
 2007-07-05  Werner Koch  <wk at g10code.com>
 
-	* t-gettime.c: New. 
+	* t-gettime.c: New.
 	* gettime.c (isotime2epoch, epoch2isotime): New.
 
 2007-07-04  Werner Koch  <wk at g10code.com>
@@ -628,7 +658,7 @@
 	(iobuf_translate_file_handle): Remove.
 	(translate_file_handle): Use new function.
 
-	* estream-printf.c [TEST]: Header including fixes. 
+	* estream-printf.c [TEST]: Header including fixes.
 	(do_format): Do not append a trailing Nul.  This avoids spurious
 	Nuls in the es_printf output.
 	(estream_vsnprintf, estream_vasprintf): Take this in account.
@@ -642,11 +672,11 @@
 	(es_convert_mode): Set O_BINARY.
 	(es_func_fd_create, es_func_fp_create, es_func_file_create) [W32]:
 	Call setmode if requested.
-	
+
 2007-06-24  Werner Koch  <wk at g10code.com>
 
 	* estream.c (do_fpopen, es_fpopen, es_fpopen_nc): New.
-	(es_func_fp_create, es_func_fp_read, es_func_fp_write) 
+	(es_func_fp_create, es_func_fp_read, es_func_fp_write)
 	(es_func_fp_seek, es_func_fp_destroy): New.
 
 2007-06-22  Werner Koch  <wk at g10code.com>
@@ -654,7 +684,7 @@
 	* estream.c (es_fdopen): Factored code out to..
 	(do_fdopen): .. new.
 	(es_fdopen_nc): New.
-	(estream_cookie_fd): Add field NO_CLOSE. 
+	(estream_cookie_fd): Add field NO_CLOSE.
 	(es_func_fd_create): Add arg NO_CLOSE and changed all callers.
 	(es_func_fd_destroy): Handle the new flag.
 
@@ -696,8 +726,8 @@
 	(agent_open): Use it if GPG_AGENT_INFO is not set.
 	(simple_pwquery): Extended to allow returning of otehyr error codes.
 
-	* util.h (GNUPG_MODULE_NAME_AGENT, GNUPG_MODULE_NAME_PINENTRY) 
-	(GNUPG_MODULE_NAME_SCDAEMON, GNUPG_MODULE_NAME_DIRMNGR) 
+	* util.h (GNUPG_MODULE_NAME_AGENT, GNUPG_MODULE_NAME_PINENTRY)
+	(GNUPG_MODULE_NAME_SCDAEMON, GNUPG_MODULE_NAME_DIRMNGR)
 	(GNUPG_MODULE_NAME_PROTECT_TOOL): New.
 	* homedir.c (gnupg_module_name): New.
 	(gnupg_bindir): New.
@@ -778,7 +808,7 @@
 2007-05-07  Werner Koch  <wk at g10code.com>
 
 	* signal.c (got_fatal_signal): Protect SIG from being clobbered by
-	a faulty signal implementaion.  Suggested by James Juran. 
+	a faulty signal implementaion.  Suggested by James Juran.
 
 2007-04-25  Werner Koch  <wk at g10code.com>
 
@@ -854,9 +884,9 @@
 
 2006-10-17  Werner Koch  <wk at g10code.com>
 
-	* estream.c (struct estream_internal, es_initialize) 
+	* estream.c (struct estream_internal, es_initialize)
 	(es_deinitialize, print_fun_writer, es_print): New and modified
-	functions to avoid tempfiles for printf style printing. 
+	functions to avoid tempfiles for printf style printing.
 
 	* Makefile.am (libcommonpth_a_SOURCES): New. We now build a secon
 	version of the library with explicit Pth support.
@@ -899,7 +929,7 @@
 	buffer.
 
 2006-09-27  Florian Weimer <fweimer at bfk.de>  (wk)
-	
+
 	* iobuf.c (iobuf_unread): New.
 
 2006-09-22  Werner Koch  <wk at g10code.com>
@@ -1086,7 +1116,7 @@
 	* estream.c (estream_cookie_mem): Make MEMORY unsigned char*.
 	(es_write): Make BUFFER a void *.
 	(es_writen): Ditto.
-	(es_func_fd_read, es_func_fd_write, es_func_mem_read) 
+	(es_func_fd_read, es_func_fd_write, es_func_mem_read)
 	(es_func_mem_write): Ditto.
 	(es_read, es_readn): Ditto.
 	(es_func_mem_write): Made MEMORY_NEW an unsigned char *.
@@ -1097,7 +1127,7 @@
 
 	* estream.c: Use HAVE_CONFIG_H and not USE_CONFIG_H!
 	(es_func_fd_read, es_func_fd_write): Protect against EINTR.
-	
+
 2005-06-01  Werner Koch  <wk at g10code.com>
 
 	* Makefile.am (AM_CPPFLAGS): Added.
@@ -1169,7 +1199,7 @@
 
 	* signal.c (got_fatal_signal, got_usr_signal)
 	(got_fatal_signal) [DOSISH]: Don't build.
-	* simple-gettext.c: Include sysutils.h 
+	* simple-gettext.c: Include sysutils.h
 
 	* homedir.c: New. Use CSIDL_APPDATA for W32 as the default home
 	directory.
@@ -1363,10 +1393,10 @@
 2003-08-14  Timo Schulz  <twoaday at freakmail.de>
 
 	* dynload.h. New. W32 wrapper around the dynload mechanism.
-	
+
 2003-07-15  Werner Koch  <wk at gnupg.org>
 
-	* simple-pwquery.c, simple-pwquery.h:  New; moved from ../agent.  
+	* simple-pwquery.c, simple-pwquery.h:  New; moved from ../agent.
 	* Makefile.am (libsimple_pwquery_a_LIBADD): New.
 
 2003-06-25  Werner Koch  <wk at gnupg.org>
@@ -1540,10 +1570,10 @@
 	* sysutils.c: New.  This is the misc.c file from gnupg 1.0.6 with
 	the OpenPGP stuff removed.
 	* sysutils.h: New.
-	
+
 2002-01-15  Werner Koch  <wk at gnupg.org>
 
-	* maperror.c: Add mapping for Not_Trusted. 
+	* maperror.c: Add mapping for Not_Trusted.
 
 2002-01-11  Werner Koch  <wk at gnupg.org>
 
@@ -1570,11 +1600,11 @@
 
 	* util.h (digitp, hexdigitp): New ctype like macros.
 	(atoi_1,atoi_2,atoi_4,xtoi_1,xtoi_2): New.
-	
-	
- Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007,
-	   2008, 2009 Free Software Foundation, Inc.
 
+
+ Copyright 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
+	   2009, 2010 Free Software Foundation, Inc.
+
  This file is free software; as a special exception the author gives
  unlimited permission to copy and/or distribute it, with or without
  modifications, as long as this notice is preserved.
@@ -1582,5 +1612,3 @@
  This file is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-		
-

Modified: trunk/common/convert.c
===================================================================
--- trunk/common/convert.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/convert.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -115,7 +115,7 @@
       size_t nbytes = n * length + 1; 
       if (length &&  (nbytes-1) / n != length) 
         {
-          errno = ENOMEM;
+          gpg_err_set_errno (ENOMEM);
           return NULL;
         }
       stringbuf = xtrymalloc (nbytes);
@@ -232,7 +232,7 @@
     {
       if (r_count)
         *r_count = 0;
-      errno = EINVAL;
+      gpg_err_set_errno (EINVAL);
       return NULL;
     }
   if (r_count)

Modified: trunk/common/estream-printf.c
===================================================================
--- trunk/common/estream-printf.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/estream-printf.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
-/* estream-printf.c - Versatile C-99 compliant printf formatting
- * Copyright (C) 2007, 2008, 2009 g10 Code GmbH
+/* estream-printf.c - Versatile mostly C-99 compliant printf formatting
+ * Copyright (C) 2007, 2008, 2009, 2010 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -15,6 +15,40 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * ALTERNATIVELY, Libestream may be distributed under the terms of the
+ * following license, in which case the provisions of this license are
+ * required INSTEAD OF the GNU General Public License. If you wish to
+ * allow use of your version of this file only under the terms of the
+ * GNU General Public License, and not to allow others to use your
+ * version of this file under the terms of the following license,
+ * indicate your decision by deleting this paragraph and the license
+ * below.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, and the entire permission notice in its entirety,
+ *    including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 /*  Required autoconf tests:
@@ -41,6 +75,13 @@
 # include <config.h>
 #endif
 
+#if defined(_WIN32) && !defined(HAVE_W32_SYSTEM)
+# define HAVE_W32_SYSTEM 1
+# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM)
+#  define HAVE_W32CE_SYSTEM
+# endif
+#endif
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -57,6 +98,9 @@
 #ifdef HAVE_LANGINFO_THOUSANDS_SEP
 #include <langinfo.h>
 #endif
+#ifdef HAVE_W32CE_SYSTEM
+#include <gpg-error.h>  /* ERRNO replacement.  */
+#endif
 #ifdef _ESTREAM_PRINTF_EXTRA_INCLUDE
 # include _ESTREAM_PRINTF_EXTRA_INCLUDE
 #endif
@@ -77,7 +121,14 @@
 #define my_printf_free(a)   free((a))
 #endif
 
+/* A wrapper to set ERRNO.  */
+#ifdef HAVE_W32CE_SYSTEM
+# define _set_errno(a)  gpg_err_set_errno ((a))
+#else
+# define _set_errno(a)  do { errno = (a); } while (0)
+#endif
 
+
 /* Calculate array dimension.  */
 #ifndef DIM
 #define DIM(array) (sizeof (array) / sizeof (*array))
@@ -634,7 +685,7 @@
   return 0; /* Success.  */
   
  leave_einval:
-  errno = EINVAL;
+  _set_errno (EINVAL);
  leave:
   if (argspecs != *argspecs_addr)
     free (argspecs);
@@ -1540,7 +1591,7 @@
   goto leave;
   
  leave_einval:
-  errno = EINVAL;
+  _set_errno (EINVAL);
  leave_error:
   rc = -1;
  leave:
@@ -1702,7 +1753,7 @@
     {
       /* Just in case some formatting routine did not checked for an
          error. */
-      errno = parm->error_flag;
+      _set_errno (parm->error_flag);
       return -1;
     }
 
@@ -1755,7 +1806,7 @@
   if (rc != -1 && parm.error_flag)
     {
       rc = -1;
-      errno = parm.error_flag;
+      _set_errno (parm.error_flag);
     }
   if (rc == -1)
     {

Modified: trunk/common/estream-printf.h
===================================================================
--- trunk/common/estream-printf.h	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/estream-printf.h	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
-/* estream-printf.h - Versatile C-99 compliant printf formatting.
- * Copyright (C) 2007 g10 Code GmbH
+/* estream-printf.h - Versatile mostly C-99 compliant printf formatting.
+ * Copyright (C) 2007, 2010 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -15,6 +15,40 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * ALTERNATIVELY, Libestream may be distributed under the terms of the
+ * following license, in which case the provisions of this license are
+ * required INSTEAD OF the GNU General Public License. If you wish to
+ * allow use of your version of this file only under the terms of the
+ * GNU General Public License, and not to allow others to use your
+ * version of this file under the terms of the following license,
+ * indicate your decision by deleting this paragraph and the license
+ * below.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, and the entire permission notice in its entirety,
+ *    including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef ESTREAM_PRINTF_H

Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/estream.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
 /* estream.c - Extended Stream I/O Library
- * Copyright (C) 2004, 2005, 2006, 2007, 2009 g10 Code GmbH
+ * Copyright (C) 2004, 2005, 2006, 2007, 2009, 2010 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -15,6 +15,40 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * ALTERNATIVELY, Libestream may be distributed under the terms of the
+ * following license, in which case the provisions of this license are
+ * required INSTEAD OF the GNU General Public License. If you wish to
+ * allow use of your version of this file only under the terms of the
+ * GNU General Public License, and not to allow others to use your
+ * version of this file under the terms of the following license,
+ * indicate your decision by deleting this paragraph and the license
+ * below.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, and the entire permission notice in its entirety,
+ *    including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifdef USE_ESTREAM_SUPPORT_H
@@ -27,6 +61,9 @@
 
 #if defined(_WIN32) && !defined(HAVE_W32_SYSTEM)
 # define HAVE_W32_SYSTEM 1
+# if defined(__MINGW32CE__) && !defined (HAVE_W32CE_SYSTEM)
+#  define HAVE_W32CE_SYSTEM
+# endif
 #endif
 
 #include <sys/types.h>
@@ -44,6 +81,9 @@
 #ifdef HAVE_W32_SYSTEM
 # include <windows.h>
 #endif
+#ifdef HAVE_W32CE_SYSTEM
+# include <gpg-error.h> /* ERRNO replacement.  */
+#endif
 
 #ifdef WITHOUT_GNU_PTH /* Give the Makefile a chance to build without Pth.  */
 # undef HAVE_PTH
@@ -76,6 +116,13 @@
 #define O_BINARY 0
 #endif
 
+#ifdef HAVE_W32CE_SYSTEM
+# define _set_errno(a)  gpg_err_set_errno ((a))
+#else
+# define _set_errno(a)  do { errno = (a); } while (0)
+#endif
+
+
 /* Generally used types.  */
 
 typedef void *(*func_realloc_t) (void *mem, size_t size);
@@ -427,7 +474,7 @@
 
   if (!data && (data_n || data_len))
     {
-      errno = EINVAL;
+      _set_errno (EINVAL);
       return -1;
     }
 
@@ -511,7 +558,7 @@
         newsize = mem_cookie->memory_size + (nleft - size);
       if (newsize < mem_cookie->offset)
         {
-          errno = EINVAL;
+          _set_errno (EINVAL);
           return -1;
         }
 
@@ -522,7 +569,7 @@
           newsize += mem_cookie->block_size - 1;
           if (newsize < mem_cookie->offset)
             {
-              errno = EINVAL;
+              _set_errno (EINVAL);
               return -1;
             }
           newsize /= mem_cookie->block_size;
@@ -532,7 +579,7 @@
       /* Check for a total limit.  */
       if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit)
         {
-          errno = ENOSPC;
+          _set_errno (ENOSPC);
           return -1;
         }
       
@@ -581,7 +628,7 @@
       break;
 
     default:
-      errno = EINVAL;
+      _set_errno (EINVAL);
       return -1;
     }
 
@@ -592,14 +639,14 @@
 
       if (!mem_cookie->flags.grow)
 	{
-	  errno = ENOSPC;
+	  _set_errno (ENOSPC);
 	  return -1;
         }
 
       newsize = pos_new + mem_cookie->block_size - 1;
       if (newsize < pos_new)
         {
-          errno = EINVAL;
+          _set_errno (EINVAL);
           return -1;
         }
       newsize /= mem_cookie->block_size;
@@ -607,7 +654,7 @@
 
       if (mem_cookie->memory_limit && newsize > mem_cookie->memory_limit)
         {
-          errno = ENOSPC;
+          _set_errno (ENOSPC);
           return -1;
         }
       
@@ -971,7 +1018,7 @@
       oflags = O_APPEND | O_CREAT;
       break;
     default:
-      errno = EINVAL;
+      _set_errno (EINVAL);
       return -1;
     }
   for (mode++; *mode; mode++)
@@ -1010,7 +1057,7 @@
 
   if (!stream->intern->func_read)
     {
-      errno = EOPNOTSUPP;
+      _set_errno (EOPNOTSUPP);
       err = -1;
     }
   else
@@ -1173,7 +1220,7 @@
       int save_errno = errno;
       fclose (stream->intern->print_fp);
       stream->intern->print_fp = NULL;
-      errno = save_errno;
+      _set_errno (save_errno);
     }
 
   func_close = stream->intern->func_close;
@@ -1460,7 +1507,7 @@
 
   if (! func_seek)
     {
-      errno = EOPNOTSUPP;
+      _set_errno (EOPNOTSUPP);
       err = -1;
       goto out;
     }
@@ -1730,7 +1777,7 @@
 
   if (stream->data_offset + size > stream->data_len)
     {
-      errno = EINVAL;
+      _set_errno (EINVAL);
       err = -1;
     }
   else
@@ -2309,7 +2356,7 @@
   else
     {
       /* FIXME?  We don't support re-opening at the moment.  */
-      errno = EINVAL;
+      _set_errno (EINVAL);
       es_deinitialize (stream);
       es_destroy (stream);
       stream = NULL;
@@ -2821,7 +2868,7 @@
     {
       /* This should never happen. If it does, the function has been
          called with wrong arguments. */
-      errno = EINVAL;
+      _set_errno (EINVAL);
       return -1;
     }
   length -= 3; /* Reserve 3 bytes for CR,LF,EOL. */
@@ -2855,7 +2902,7 @@
               if (max_length)
                 *max_length = 0;
               ESTREAM_UNLOCK (stream);
-              errno = save_errno;
+              _set_errno (save_errno);
               return -1;
             }
           buffer = *addr_of_buffer;
@@ -2973,21 +3020,32 @@
 {
 #ifdef HAVE_W32_SYSTEM
   int attempts, n;
+#ifdef HAVE_W32CE_SYSTEM
+  wchar_t buffer[MAX_PATH+9+12+1];
+# define mystrlen(a) wcslen (a)
+  wchar_t *name, *p;
+#else
   char buffer[MAX_PATH+9+12+1];
+# define mystrlen(a) strlen (a)
   char *name, *p;
+#endif
   HANDLE file;
   int pid = GetCurrentProcessId ();
   unsigned int value;
   int i;
   
   n = GetTempPath (MAX_PATH+1, buffer);
-  if (!n || n > MAX_PATH || strlen (buffer) > MAX_PATH)
+  if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH)
     {
-      errno = ENOENT;
+      _set_errno (ENOENT);
       return -1;
     }
-  p = buffer + strlen (buffer);
+  p = buffer + mystrlen (buffer);
+#ifdef HAVE_W32CE_SYSTEM
+  wcscpy (p, L"_estream");
+#else
   strcpy (p, "_estream");
+#endif
   p += 8;
   /* We try to create the directory but don't care about an error as
      it may already exist and the CreateFile would throw an error
@@ -3004,7 +3062,11 @@
           *p++ = tohex (((value >> 28) & 0x0f));
           value <<= 4;
         }
+#ifdef HAVE_W32CE_SYSTEM
+      wcscpy (p, L".tmp");
+#else
       strcpy (p, ".tmp");
+#endif
       file = CreateFile (buffer,
                          GENERIC_READ | GENERIC_WRITE,
                          0,
@@ -3014,17 +3076,21 @@
                          NULL);
       if (file != INVALID_HANDLE_VALUE)
         {
+#ifdef HAVE_W32CE_SYSTEM
+          int fd = (int)file;
+#else
           int fd = _open_osfhandle ((long)file, 0);
           if (fd == -1)
             {
               CloseHandle (file);
               return -1;
             }
+#endif
           return fd;
         }
       Sleep (1); /* One ms as this is the granularity of GetTickCount.  */
     }
-  errno = ENOENT;
+  _set_errno (ENOENT);
   return -1;
 #else /*!HAVE_W32_SYSTEM*/
   FILE *fp;
@@ -3109,7 +3175,7 @@
     }
   else
     {
-      errno = EINVAL;
+      _set_errno (EINVAL);
       err = -1;
     }
 

Modified: trunk/common/estream.h
===================================================================
--- trunk/common/estream.h	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/estream.h	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
 /* estream.h - Extended stream I/O Library
- * Copyright (C) 2004, 2005, 2006, 2007 g10 Code GmbH
+ * Copyright (C) 2004, 2005, 2006, 2007, 2010 g10 Code GmbH
  *
  * This file is part of Libestream.
  *
@@ -15,6 +15,40 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with Libestream; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * ALTERNATIVELY, Libestream may be distributed under the terms of the
+ * following license, in which case the provisions of this license are
+ * required INSTEAD OF the GNU General Public License. If you wish to
+ * allow use of your version of this file only under the terms of the
+ * GNU General Public License, and not to allow others to use your
+ * version of this file under the terms of the following license,
+ * indicate your decision by deleting this paragraph and the license
+ * below.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, and the entire permission notice in its entirety,
+ *    including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #ifndef ESTREAM_H

Modified: trunk/common/gettime.c
===================================================================
--- trunk/common/gettime.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/gettime.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -500,7 +500,7 @@
 dump_isotime (const gnupg_isotime_t t)
 {
   if (!t || !*t)
-    log_printf (_("[none]"));
+    log_printf ("%s", _("[none]"));
   else
     log_printf ("%.4s-%.2s-%.2s %.2s:%.2s:%s",
                 t, t+4, t+6, t+9, t+11, t+13);

Modified: trunk/common/homedir.c
===================================================================
--- trunk/common/homedir.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/homedir.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
 /* homedir.c - Setup the home directory.
- *	Copyright (C) 2004, 2006, 2007 Free Software Foundation, Inc.
+ * Copyright (C) 2004, 2006, 2007, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -114,7 +114,18 @@
           
           /* Try to create the directory if it does not yet exists.  */
           if (access (dir, F_OK))
-            CreateDirectory (dir, NULL);
+            {
+#ifdef HAVE_W32CE_SYSTEM
+              wchar_t *wdir = utf8_to_wchar (dir);
+              if (wdir)
+                {
+                  CreateDirectory (wdir, NULL);
+                  xfree (wdir);
+                }
+#else              
+              CreateDirectory (dir, NULL);
+#endif
+            }
         }
       else
         dir = GNUPG_DEFAULT_HOMEDIR;
@@ -178,8 +189,20 @@
   if (!got_dir)
     {
       char *p;
+      int rc;
 
-      if ( !GetModuleFileName ( NULL, dir, MAX_PATH) )
+#ifdef HAVE_W32CE_SYSTEM
+      {
+        wchar_t wdir [MAX_PATH+5];
+        rc = GetModuleFileName (NULL, wdir, MAX_PATH);
+        if (rc && WideCharToMultiByte (CP_UTF8, 0, wdir, -1, dir, MAX_PATH-4,
+                                       NULL, NULL) < 0)
+          rc = 0;
+      }
+#else
+      rc = GetModuleFileName (NULL, dir, MAX_PATH);
+#endif
+      if (!rc)
         {
           log_debug ("GetModuleFileName failed: %s\n", w32_strerror (0));
           *dir = 0;

Modified: trunk/common/http.c
===================================================================
--- trunk/common/http.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/http.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1225,7 +1225,7 @@
 	      int save_errno = errno;
 	      xfree (buffer);
 	      *length_of_buffer = *max_length = 0;
-	      errno = save_errno;
+	      gpg_err_set_errno (save_errno);
 	      return 0;
 	    }
 	  buffer = *addr_of_buffer;
@@ -1548,12 +1548,13 @@
   int srv, connected;
   int last_errno = 0;
   struct srventry *serverlist = NULL;
-
+#ifdef HAVE_W32_SYSTEM
+  unsigned long inaddr;
+#endif
   /* Not currently using the flags */
   (void)flags;
 
 #ifdef HAVE_W32_SYSTEM
-  unsigned long inaddr;
 
 #ifndef HTTP_NO_WSASTARTUP
   init_sockets ();
@@ -1724,7 +1725,7 @@
 #endif
       if (sock != -1)
 	sock_close (sock);
-      errno = last_errno;
+      gpg_err_set_errno (last_errno);
       return -1;
     }
   return sock;
@@ -1805,7 +1806,7 @@
           if (nread == GNUTLS_E_REHANDSHAKE)
             goto again; /* A client is allowed to just ignore this request. */
           log_info ("TLS network read failed: %s\n", gnutls_strerror (nread));
-          errno = EIO;
+          gpg_err_set_errno (EIO);
           return -1;
         }
     }
@@ -1856,7 +1857,7 @@
                 }
               log_info ("TLS network write failed: %s\n",
                         gnutls_strerror (nwritten));
-              errno = EIO;
+              gpg_err_set_errno (EIO);
               return -1;
             }
           nleft -= nwritten;
@@ -1868,7 +1869,7 @@
     {
       if ( write_server (c->fd, buffer, size) )
         {
-          errno = EIO;
+          gpg_err_set_errno (EIO);
           nwritten = -1;
         }
       else

Modified: trunk/common/i18n.c
===================================================================
--- trunk/common/i18n.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/i18n.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -1,5 +1,5 @@
 /* i18n.c - gettext initialization
- *	Copyright (C) 2007 Free Software Foundation, Inc.
+ *	Copyright (C) 2007, 2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -51,8 +51,8 @@
 i18n_switchto_utf8 (void)
 {
 #ifdef USE_SIMPLE_GETTEXT
-  gettext_select_utf8 (1);
-  return NULL;
+  /* Return an arbitrary pointer as true value.  */
+  return gettext_use_utf8 (1) ? (char*)(-1) : NULL;
 #elif defined(ENABLE_NLS)
   char *orig_codeset = bind_textdomain_codeset (PACKAGE_GT, NULL);
 # ifdef HAVE_LANGINFO_CODESET
@@ -82,8 +82,7 @@
 i18n_switchback (char *saved_codeset)
 {
 #ifdef USE_SIMPLE_GETTEXT
-  (void)saved_codeset;
-  gettext_select_utf8 (0);
+  gettext_use_utf8 (!!saved_codeset);
 #elif defined(ENABLE_NLS)
   if (saved_codeset)
     {

Modified: trunk/common/iobuf.c
===================================================================
--- trunk/common/iobuf.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/iobuf.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -306,7 +306,21 @@
       sm = FILE_SHARE_READ;
     }
 
+#ifdef HAVE_W32CE_SYSTEM
+  {
+    wchar_t *wfname = utf8_to_wchar (fname);
+    if (wfname)
+      {
+        hfile = CreateFile (wfname, da, sm, NULL, cd,
+                            FILE_ATTRIBUTE_NORMAL, NULL);
+        xfree (wfname);
+      }
+    else
+      hfile = INVALID_HANDLE_VALUE;
+  }
+#else
   hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL);
+#endif
   return hfile;
 #else /*!HAVE_W32_SYSTEM*/
   int oflag;
@@ -1188,7 +1202,14 @@
     {
       /* Argg, MSDOS does not allow to remove open files.  So
        * we have to do it here */
+#ifdef HAVE_W32CE_SYSTEM
+      wchar_t *wtmp = utf8_to_wchar (remove_name);
+      if (wtmp)
+        DeleteFile (wtmp);
+      xfree (wtmp);
+#else
       remove (remove_name);
+#endif
       xfree (remove_name);
     }
 #endif

Modified: trunk/common/membuf.c
===================================================================
--- trunk/common/membuf.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/membuf.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -105,7 +105,7 @@
           xfree (mb->buf);
           mb->buf = NULL;
         }
-      errno = mb->out_of_core;
+      gpg_err_set_errno (mb->out_of_core);
       return NULL;
     }
 

Modified: trunk/common/signal.c
===================================================================
--- trunk/common/signal.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/signal.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -21,7 +21,9 @@
 #include <config.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <signal.h>
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>

Modified: trunk/common/sysutils.c
===================================================================
--- trunk/common/sysutils.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/sysutils.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -130,31 +130,20 @@
 
 
 
-/* Return a string which is used as a kind of process ID */
+/* Return a string which is used as a kind of process ID.  */
 const byte *
-get_session_marker( size_t *rlen )
+get_session_marker (size_t *rlen)
 {
-    static byte marker[SIZEOF_UNSIGNED_LONG*2];
-    static int initialized;
-
-    if ( !initialized ) {
-        volatile ulong aa, bb; /* we really want the uninitialized value */
-        ulong a, b;
-
-        initialized = 1;
-        /* Although this marker is guessable it is not easy to use
-         * for a faked control packet because an attacker does not
-         * have enough control about the time the verification does 
-         * take place.  Of course, we can add just more random but 
-         * than we need the random generator even for verification
-         * tasks - which does not make sense. */
-        a = aa ^ (ulong)getpid();
-        b = bb ^ (ulong)time(NULL);
-        memcpy( marker, &a, SIZEOF_UNSIGNED_LONG );
-        memcpy( marker+SIZEOF_UNSIGNED_LONG, &b, SIZEOF_UNSIGNED_LONG );
+  static byte marker[SIZEOF_UNSIGNED_LONG*2];
+  static int initialized;
+  
+  if (!initialized)
+    {
+      gcry_create_nonce (marker, sizeof marker);
+      initialized = 1;
     }
-    *rlen = sizeof(marker);
-    return marker;
+  *rlen = sizeof (marker);
+  return marker;
 }
 
 
@@ -286,7 +275,10 @@
 int
 translate_sys2libc_fd (gnupg_fd_t fd, int for_write)
 {
-#ifdef HAVE_W32_SYSTEM
+#if defined(HAVE_W32CE_SYSTEM)
+  (void)for_write;
+  return (int)fd;
+#elif defined(HAVE_W32_SYSTEM)
   int x;
 
   if (fd == GNUPG_INVALID_FD)
@@ -331,8 +323,15 @@
 {
 #ifdef HAVE_W32_SYSTEM
   int attempts, n;
+#ifdef HAVE_W32CE_SYSTEM
+  wchar_t buffer[MAX_PATH+7+12+1];
+# define mystrlen(a) wcslen (a)
+  wchar_t *name, *p;
+#else
   char buffer[MAX_PATH+7+12+1];
+# define mystrlen(a) strlen (a)
   char *name, *p;
+#endif
   HANDLE file;
   int pid = GetCurrentProcessId ();
   unsigned int value;
@@ -344,13 +343,18 @@
   sec_attr.bInheritHandle = TRUE;
 
   n = GetTempPath (MAX_PATH+1, buffer);
-  if (!n || n > MAX_PATH || strlen (buffer) > MAX_PATH)
+  if (!n || n > MAX_PATH || mystrlen (buffer) > MAX_PATH)
     {
-      errno = ENOENT;
+      gpg_err_set_errno (ENOENT);
       return NULL;
     }
-  p = buffer + strlen (buffer);
+  p = buffer + mystrlen (buffer);
+#ifdef HAVE_W32CE_SYSTEM
+  wcscpy (p, L"_gnupg");
+  p += 7;
+#else
   p = stpcpy (p, "_gnupg");
+#endif
   /* We try to create the directory but don't care about an error as
      it may already exist and the CreateFile would throw an error
      anyway.  */
@@ -366,7 +370,11 @@
           *p++ = tohex (((value >> 28) & 0x0f));
           value <<= 4;
         }
+#ifdef HAVE_W32CE_SYSTEM
+      wcscpy (p, L".tmp");
+#else
       strcpy (p, ".tmp");
+#endif
       file = CreateFile (buffer,
                          GENERIC_READ | GENERIC_WRITE,
                          0,
@@ -377,6 +385,10 @@
       if (file != INVALID_HANDLE_VALUE)
         {
           FILE *fp;
+#ifdef HAVE_W32CE_SYSTEM
+          int fd = (int)file;
+          fp = _wfdopen (fd, L"w+b");
+#else
           int fd = _open_osfhandle ((long)file, 0);
           if (fd == -1)
             {
@@ -384,19 +396,21 @@
               return NULL;
             }
           fp = fdopen (fd, "w+b");
+#endif
           if (!fp)
             {
               int save = errno;
               close (fd);
-              errno = save;
+              gpg_err_set_errno (save);
               return NULL;
             }
           return fp;
         }
       Sleep (1); /* One ms as this is the granularity of GetTickCount.  */
     }
-  errno = ENOENT;
+  gpg_err_set_errno (ENOENT);
   return NULL;
+#undef mystrlen
 #else /*!HAVE_W32_SYSTEM*/
   return tmpfile ();
 #endif /*!HAVE_W32_SYSTEM*/
@@ -490,3 +504,18 @@
                (unsigned long)pid, w32_strerror (-1));
 #endif
 }
+
+
+
+#ifdef HAVE_W32CE_SYSTEM
+/* Replacement for getenv which takes care of the our use of getenv.
+   The code is not thread safe but we expect it to work in all cases
+   because it is called for the first time early enough.  */
+char *
+_gnupg_getenv (const char *name)
+{
+  (void)name;
+  return NULL;
+}
+#endif /*HAVE_W32CE_SYSTEM*/
+

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/util.h	2010-03-02 21:25:08 UTC (rev 5275)
@@ -300,7 +300,14 @@
 }
 #endif /* !HAVE_TTYNAME */
 
+#ifdef HAVE_W32CE_SYSTEM
+#define getpid() GetCurrentProcessId ()
+char *_gnupg_getenv (const char *name); /* See sysutils.c */
+#define getenv(a)  _gnupg_getenv ((a))
+#endif
 
+
+
 /*-- Macros to replace ctype ones to avoid locale problems. --*/
 #define spacep(p)   (*(p) == ' ' || *(p) == '\t')
 #define digitp(p)   (*(p) >= '0' && *(p) <= '9')

Modified: trunk/common/xreadline.c
===================================================================
--- trunk/common/xreadline.c	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/common/xreadline.c	2010-03-02 21:25:08 UTC (rev 5275)
@@ -98,7 +98,7 @@
               *length_of_buffer = 0;
               if (max_length)
                 *max_length = 0;
-              errno = save_errno;
+              gpg_err_set_errno (save_errno);
               return -1;
             }
           buffer = *addr_of_buffer;

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2010-03-01 12:49:17 UTC (rev 5274)
+++ trunk/configure.ac	2010-03-02 21:25:08 UTC (rev 5275)
@@ -999,8 +999,8 @@
 #
 AC_MSG_NOTICE([checking for header files])
 AC_HEADER_STDC
-AC_CHECK_HEADERS([string.h unistd.h langinfo.h termio.h locale.h getopt.h])
-AC_CHECK_HEADERS([pty.h pwd.h inttypes.h])
+AC_CHECK_HEADERS([string.h unistd.h langinfo.h termio.h locale.h getopt.h \
+                  pty.h pwd.h inttypes.h signal.h])
 AC_HEADER_TIME
 
 




More information about the Gnupg-commits mailing list