[git] GnuPG - branch, master, updated. gnupg-2.1.8-53-gc8584a1

by Neal H. Walfield cvs at cvs.gnupg.org
Wed Sep 30 13:00:42 CEST 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  c8584a1e559bc720412e1a2fc546a54ff4517205 (commit)
       via  5576146ede40b42bc632fd9697dd429a4d1409cf (commit)
       via  270d3f55f9193ebda5e1b642d58daf905019914d (commit)
      from  8ab63e4b5018044ecfb0b9910412487066886826 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit c8584a1e559bc720412e1a2fc546a54ff4517205
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Sep 29 14:12:00 2015 +0200

    common: Add mkdir_p.
    
    * common/mkdir_p.c: New file.
    * common/mkdir_p.h: New file.
    * common/Makefile.am (common_sources): Add mkdir_p.c and mkdir_p.h.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>.

diff --git a/common/Makefile.am b/common/Makefile.am
index 47facd4..7c87fa9 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -86,7 +86,8 @@ common_sources = \
 	openpgp-oid.c \
 	ssh-utils.c ssh-utils.h \
 	agent-opt.c \
-	helpfile.c
+	helpfile.c \
+	mkdir_p.c mkdir_p.h
 
 if HAVE_W32_SYSTEM
 common_sources += w32-reg.c w32-afunix.c w32-afunix.h
diff --git a/common/mkdir_p.c b/common/mkdir_p.c
new file mode 100644
index 0000000..6a54600
--- /dev/null
+++ b/common/mkdir_p.c
@@ -0,0 +1,161 @@
+/* mkdir_p.c - Create a directory and any missing parents.
+ * Copyright (C) 2015 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <assert.h>
+#include <stdarg.h>
+
+#include "mkdir_p.h"
+#include "stringhelp.h"
+#include "logging.h"
+#include "util.h"
+
+#define DEBUG 0
+
+int
+amkdir_p (char **directory_components)
+{
+  int count;
+  char **dirs;
+  int i;
+  int rc;
+
+  for (count = 0; directory_components[count]; count ++)
+    ;
+
+  if (DEBUG)
+    log_debug ("%s: %d directory components.\n", __func__, count);
+
+  dirs = xcalloc (count, sizeof (char *));
+  for (i = 0; directory_components[i]; i ++)
+    {
+      if (i == 0)
+	dirs[i] = directory_components[i];
+      else
+	dirs[i] = make_filename (dirs[i - 1], directory_components[i], NULL);
+
+      if (DEBUG)
+	log_debug ("%s: Directory %d: `%s'.\n", __func__, i, dirs[i]);
+    }
+
+  for (i = count - 1; i >= 0; i --)
+    {
+      struct stat s;
+
+      if (DEBUG)
+	log_debug ("%s: stat(%s)\n", __func__, dirs[i]);
+
+      rc = stat (dirs[i], &s);
+      if (rc == 0 && ! S_ISDIR (s.st_mode))
+	{
+	  if (DEBUG)
+	    log_debug ("%s: %s exists, but is not a directory!\n",
+		       __func__, dirs[i]);
+	  rc = gpg_error (GPG_ERR_ENOTDIR);
+	  goto out;
+	}
+      else if (rc == 0)
+	{
+	  /* Got a directory.  */
+	  if (DEBUG)
+	    log_debug ("%s: %s exists and is a directory!\n",
+		       __func__, dirs[i]);
+	  break;
+	}
+      else if (errno == ENOENT)
+	/* This directory does not exist yet.  Continue walking up the
+	   hierarchy.  */
+	{
+	  if (DEBUG)
+	    log_debug ("%s: %s does not exist!\n",
+		       __func__, dirs[i]);
+	  continue;
+	}
+      else
+	/* Some other error code.  Die.  Note: this could be ENOTDIR
+	   (we return this above), which means that a component of the
+	   path prefix is not a directory.  */
+	{
+	  if (DEBUG)
+	    log_debug ("%s: stat(%s) => %s!\n",
+		       __func__, dirs[i], strerror (errno));
+	  rc = gpg_error_from_syserror ();
+	  goto out;
+	}
+    }
+
+  assert (i >= -1);
+  /* DIRS[I] exists.  Start with the following entry.  */
+  i ++;
+
+  for (; i < count; i ++)
+    {
+      if (DEBUG)
+	log_debug ("Creating directory: %s\n", dirs[i]);
+
+      rc = mkdir (dirs[i], S_IRUSR | S_IWUSR | S_IXUSR);
+      if (rc)
+	{
+	  rc = gpg_error_from_syserror ();
+	  goto out;
+	}
+    }
+
+ out:
+  for (i = 1; i < count; i ++)
+    xfree (dirs[i]);
+  xfree (dirs);
+
+  if (DEBUG)
+    log_debug ("%s: Returning %s\n", __func__, gpg_strerror (rc));
+
+  return rc;
+}
+
+int
+mkdir_p (char *directory_component, ...)
+{
+  va_list ap;
+  int i;
+  int space = 1;
+  char **dirs = xmalloc (space * sizeof (char *));
+  int rc;
+
+  dirs[0] = directory_component;
+
+  va_start (ap, directory_component);
+  for (i = 1; dirs[i - 1]; i ++)
+    {
+      if (i == space)
+	{
+	  space = 2 * space;
+	  dirs = xrealloc (dirs, space * sizeof (char *));
+	}
+      dirs[i] = va_arg (ap, char *);
+    }
+  va_end (ap);
+
+  rc = amkdir_p (dirs);
+
+  xfree (dirs);
+
+  return rc;
+}
diff --git a/common/mkdir_p.h b/common/mkdir_p.h
new file mode 100644
index 0000000..ddf412b
--- /dev/null
+++ b/common/mkdir_p.h
@@ -0,0 +1,42 @@
+/* mkdir_p.h - Create a directory and any missing parents.
+ * Copyright (C) 2015 g10 Code GmbH
+ *
+ * This file is part of GnuPG.
+ *
+ * GnuPG is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * GnuPG is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MKDIR_P_H
+#define MKDIR_P_H
+
+#include "types.h"
+
+/* Create a directory as well as any missing parents.
+
+   The arguments must be NULL termianted.  If DIRECTORY_COMPONENTS...
+   consists of two elements, "foo/bar" and "xyzzy", this function will
+   first try to create the directory "foo/bar" and then the directory
+   "foo/bar/xyzzy".  On success returns 0, otherwise an error code is
+   returned.  */
+int mkdir_p (char *directory_component, ...) GPGRT_ATTR_SENTINEL(0);
+
+/* Like mkdir_p, but DIRECTORY_COMPONENTS is a NULL terminated
+   array, e.g.:
+
+     char **dirs = { "foo", "bar", NULL };
+     amkdir_p (dirs);
+ */
+int amkdir_p (char **directory_components);
+
+#endif

commit 5576146ede40b42bc632fd9697dd429a4d1409cf
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Sep 29 13:24:48 2015 +0200

    common: Remove unused files.
    
    * common/xmalloc.c: Remove file.
    * common/xmalloc.h: Remove file.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>.

diff --git a/common/xmalloc.c b/common/xmalloc.c
deleted file mode 100644
index 0690a36..0000000
--- a/common/xmalloc.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/* xmalloc.c -	standard malloc wrappers
- *	Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify it
- * under the terms of either
- *
- *   - the GNU Lesser General Public License as published by the Free
- *     Software Foundation; either version 3 of the License, or (at
- *     your option) any later version.
- *
- * or
- *
- *   - the GNU General Public License as published by the Free
- *     Software Foundation; either version 2 of the License, or (at
- *     your option) any later version.
- *
- * or both in parallel, as here.
- *
- * GnuPG is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copies of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "libjnlib-config.h"
-#include "xmalloc.h"
-
-static void
-out_of_core(void)
-{
-    fputs("\nfatal: out of memory\n", stderr );
-    exit(2);
-}
-
-
-void *
-xmalloc( size_t n )
-{
-    void *p;
-
-    /* Make sure that xmalloc (0) works.  This is the same behaviour
-       has in gpg 2.x.  Note that in contrast to this code, Libgcrypt
-       (and thus most xmallocs in gpg 2.x) detect the !n and bail out.  */
-    if (!n)
-      n = 1;
-
-    p = malloc( n );
-    if( !p )
-	out_of_core();
-    return p;
-}
-
-void *
-xrealloc( void *a, size_t n )
-{
-    void *p = realloc( a, n );
-    if( !p )
-	out_of_core();
-    return p;
-}
-
-void *
-xcalloc( size_t n, size_t m )
-{
-    void *p;
-
-    if (!n)
-      n = 1;
-    if (!m)
-      m = 1;
-
-    p = calloc( n, m );
-    if( !p )
-	out_of_core();
-    return p;
-}
-
-char *
-xstrdup( const char *string )
-{
-    void *p = xmalloc( strlen(string)+1 );
-    strcpy( p, string );
-    return p;
-}
-
-
-char *
-xstrcat2( const char *a, const char *b )
-{
-    size_t n1;
-    char *p;
-
-    if( !b )
-	return xstrdup( a );
-
-    n1 = strlen(a);
-    p = xmalloc( n1 + strlen(b) + 1 );
-    memcpy(p, a, n1 );
-    strcpy(p+n1, b );
-    return p;
-}
diff --git a/common/xmalloc.h b/common/xmalloc.h
deleted file mode 100644
index d91883d..0000000
--- a/common/xmalloc.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/* xmalloc.h
- *	Copyright (C) 1999, 2000, 2001, 2006 Free Software Foundation, Inc.
- *
- * This file is part of GnuPG.
- *
- * GnuPG is free software; you can redistribute it and/or modify it
- * under the terms of either
- *
- *   - the GNU Lesser General Public License as published by the Free
- *     Software Foundation; either version 3 of the License, or (at
- *     your option) any later version.
- *
- * or
- *
- *   - the GNU General Public License as published by the Free
- *     Software Foundation; either version 2 of the License, or (at
- *     your option) any later version.
- *
- * or both in parallel, as here.
- *
- * GnuPG is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copies of the GNU General Public License
- * and the GNU Lesser General Public License along with this program;
- * if not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef GNUPG_COMMON_XMALLOC_H
-#define GNUPG_COMMON_XMALLOC_H
-
-void *xmalloc( size_t n );
-void *xrealloc( void *a, size_t n );
-void *xcalloc( size_t n, size_t m );
-char *xstrdup( const char *string );
-char *xstrcat2( const char *a, const char *b );
-
-
-#endif /*GNUPG_COMMON_XMALLOC_H*/

commit 270d3f55f9193ebda5e1b642d58daf905019914d
Author: Neal H. Walfield <neal at g10code.com>
Date:   Tue Sep 29 13:20:26 2015 +0200

    common: Include <gpg-error.h>.
    
    * common/logging.h: Include <gpg-error.h>.
    
    --
    Signed-off-by: Neal H. Walfield <neal at g10code.com>.
    
    logging.h uses estream_t and as such should directly include
    <gpg-error.h>.

diff --git a/common/logging.h b/common/logging.h
index dbfc8ba..c4ae5d0 100644
--- a/common/logging.h
+++ b/common/logging.h
@@ -34,6 +34,7 @@
 
 #include <stdio.h>
 #include <stdarg.h>
+#include <gpg-error.h>
 #include "mischelp.h"
 #include "w32help.h"
 

-----------------------------------------------------------------------

Summary of changes:
 common/Makefile.am |   3 +-
 common/logging.h   |   1 +
 common/mkdir_p.c   | 161 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 common/mkdir_p.h   |  42 ++++++++++++++
 common/xmalloc.c   | 112 -------------------------------------
 common/xmalloc.h   |  41 --------------
 6 files changed, 206 insertions(+), 154 deletions(-)
 create mode 100644 common/mkdir_p.c
 create mode 100644 common/mkdir_p.h
 delete mode 100644 common/xmalloc.c
 delete mode 100644 common/xmalloc.h


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list