gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r21850 - in gnunet/src: include testing util


From: gnunet
Subject: [GNUnet-SVN] r21850 - in gnunet/src: include testing util
Date: Sun, 10 Jun 2012 12:48:29 +0200

Author: grothoff
Date: 2012-06-10 12:48:29 +0200 (Sun, 10 Jun 2012)
New Revision: 21850

Modified:
   gnunet/src/include/gnunet_disk_lib.h
   gnunet/src/testing/testing.c
   gnunet/src/util/disk.c
Log:
-integrate mkdirp with testing

Modified: gnunet/src/include/gnunet_disk_lib.h
===================================================================
--- gnunet/src/include/gnunet_disk_lib.h        2012-06-10 10:08:44 UTC (rev 
21849)
+++ gnunet/src/include/gnunet_disk_lib.h        2012-06-10 10:48:29 UTC (rev 
21850)
@@ -356,6 +356,21 @@
 
 
 /**
+ * Create an (empty) temporary file on disk.  If the given name is not
+ * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
+ * 6 random characters will be appended to the name to create a unique
+ * filename.
+ *
+ * @param t component to use for the name;
+ *        does NOT contain "XXXXXX" or "/tmp/".
+ * @return NULL on error, otherwise name of fresh
+ *         file on disk in directory for temporary files
+ */
+char *
+GNUNET_DISK_mkdtemp (const char *t);
+
+
+/**
  * Open a file.  Note that the access permissions will only be
  * used if a new file is created and if the underlying operating
  * system supports the given permissions.

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2012-06-10 10:08:44 UTC (rev 21849)
+++ gnunet/src/testing/testing.c        2012-06-10 10:48:29 UTC (rev 21850)
@@ -65,8 +65,7 @@
 {
   /**
    * Prefix (i.e. "/tmp/gnunet-testing/") we prepend to each
-   * SERVICEHOME. 
-   */
+   * SERVICEHOME.    */
   char *tmppath;
 
   /**

Modified: gnunet/src/util/disk.c
===================================================================
--- gnunet/src/util/disk.c      2012-06-10 10:08:44 UTC (rev 21849)
+++ gnunet/src/util/disk.c      2012-06-10 10:48:29 UTC (rev 21850)
@@ -393,21 +393,15 @@
 
 
 /**
- * Create an (empty) temporary file on disk.  If the given name is not
- * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
- * 6 random characters will be appended to the name to create a unique
- * filename.
+ * Create the name for a temporary file or directory from a template.
  *
- * @param t component to use for the name;
- *        does NOT contain "XXXXXX" or "/tmp/".
- * @return NULL on error, otherwise name of fresh
- *         file on disk in directory for temporary files
+ * @param t template (without XXXXX or "/tmp/")
+ * @return name ready for passing to 'mktemp' or 'mkdtemp', NULL on error
  */
-char *
-GNUNET_DISK_mktemp (const char *t)
+static char *
+mktemp_name (const char *t)
 {
   const char *tmpdir;
-  int fd;
   char *tmpl;
   char *fn;
 
@@ -419,7 +413,12 @@
   {
     /* FIXME: This uses system codepage on W32, not UTF-8 */
     tmpdir = getenv ("TMPDIR");
-    tmpdir = tmpdir ? tmpdir : "/tmp";
+    if (NULL == tmpdir)
+      tmpdir = getenv ("TMP");
+    if (NULL == tmpdir)
+      tmpdir = getenv ("TEMP");  
+    if (NULL == tmpdir)
+      tmpdir = "/tmp";
     GNUNET_asprintf (&tmpl, "%s/%s%s", tmpdir, t, "XXXXXX");
   }
   else
@@ -438,17 +437,61 @@
 #else
   fn = tmpl;
 #endif
-  /* FIXME: why is this not MKSTEMP()? This function is implemented in plibc.
-   * CG: really? If I put MKSTEMP here, I get a compilation error...
-   * It will assume that fn is UTF-8-encoded, if compiled with UTF-8 support.
-   */
-  fd = mkstemp (fn);
-  if (fd == -1)
+  return fn;
+}
+
+
+/**
+ * Create an (empty) temporary directory on disk.  If the given name is not
+ * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
+ * 6 random characters will be appended to the name to create a unique
+ * filename.
+ *
+ * @param t component to use for the name;
+ *        does NOT contain "XXXXXX" or "/tmp/".
+ * @return NULL on error, otherwise name of fresh
+ *         file on disk in directory for temporary files
+ */
+char *
+GNUNET_DISK_mkdtemp (const char *t)
+{
+  char *fn;
+
+  fn = mktemp_name (t);
+  if (fn != mkdtemp (fn))
   {
     LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
     GNUNET_free (fn);
     return NULL;
   }
+  return fn;
+}
+
+
+/**
+ * Create an (empty) temporary file on disk.  If the given name is not
+ * an absolute path, the current 'TMPDIR' will be prepended.  In any case,
+ * 6 random characters will be appended to the name to create a unique
+ * filename.
+ *
+ * @param t component to use for the name;
+ *        does NOT contain "XXXXXX" or "/tmp/".
+ * @return NULL on error, otherwise name of fresh
+ *         file on disk in directory for temporary files
+ */
+char *
+GNUNET_DISK_mktemp (const char *t)
+{
+  int fd;
+  char *fn;
+
+  fn = mktemp_name (t);
+  if (-1 == (fd = mkstemp (fn)))
+  {
+    LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "mkstemp", fn);
+    GNUNET_free (fn);
+    return NULL;
+  }
   if (0 != CLOSE (fd))
     LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "close", fn);
   return fn;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]