projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Makefiles: Make a couple of targets build more quietly.
[pspp]
/
src
/
libpspp
/
temp-file.c
diff --git
a/src/libpspp/temp-file.c
b/src/libpspp/temp-file.c
index 9d3c392659753043667af822b9bbfe7bd3e1b0f0..cc90a37559b2cb532e8cc60f5589da531b8bd211 100644
(file)
--- a/
src/libpspp/temp-file.c
+++ b/
src/libpspp/temp-file.c
@@
-40,9
+40,10
@@
*/
*/
+static void cleanup (void);
static struct temp_dir *temp_dir;
static struct temp_dir *temp_dir;
-struct hmapx map;
+st
atic st
ruct hmapx map;
static void
setup (void)
static void
setup (void)
@@
-51,6
+52,30
@@
setup (void)
temp_dir = create_temp_dir ("pspp", NULL, true);
}
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)
{
static void
cleanup (void)
{
@@
-74,17
+99,13
@@
create_temp_file (void)
char *file_name;
FILE *stream;
char *file_name;
FILE *stream;
+ initialise ();
if (temp_dir == NULL)
if (temp_dir == NULL)
- {
- setup ();
- if (temp_dir == NULL)
- return NULL;
- atexit (cleanup);
- }
+ return NULL;
file_name = xasprintf ("%s/%d", temp_dir->dir_name, idx++);
register_temp_file (temp_dir, file_name);
file_name = xasprintf ("%s/%d", temp_dir->dir_name, idx++);
register_temp_file (temp_dir, file_name);
- stream = fopen_temp (file_name, "wb+");
+ stream = fopen_temp (file_name, "wb+"
, true
);
if (stream == NULL)
unregister_temp_file (temp_dir, file_name);
else
if (stream == NULL)
unregister_temp_file (temp_dir, file_name);
else
@@
-104,7
+125,7
@@
close_temp_file (FILE *file)
struct hmapx_node *node = hmapx_first_with_hash (&map, hash_pointer (file, 0));
char *fn = node->data;
fclose_temp (file);
struct hmapx_node *node = hmapx_first_with_hash (&map, hash_pointer (file, 0));
char *fn = node->data;
fclose_temp (file);
- cleanup_temp_file (temp_dir, fn);
+ cleanup_temp_file (temp_dir, fn);
hmapx_delete (&map, node);
free (fn);
}
hmapx_delete (&map, node);
free (fn);
}