+
+static void cleanup (void);
+
+static struct temp_dir *temp_dir;
+struct hmapx map;
+
+static void
+setup (void)
+{
+ hmapx_init (&map);
+ temp_dir = create_temp_dir ("pspp", NULL, true);
+}
+
+static void
+initialise (void)
+{
+ if (temp_dir == NULL)
+ {
+ setup ();
+ if (temp_dir == NULL)
+ return ;
+ atexit (cleanup);
+ }
+}
+
+
+const char *
+temp_dir_name (void)
+{
+ initialise ();
+
+ if (temp_dir)
+ return temp_dir->dir_name;
+
+ return NULL;
+}
+
+static void
+cleanup (void)
+{
+ struct hmapx_node *node;
+ char *fn;
+
+ cleanup_temp_dir (temp_dir);
+
+ HMAPX_FOR_EACH (fn, node, &map)
+ {
+ free (fn);
+ }
+
+ hmapx_destroy (&map);
+}
+