X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Ftemp-file.c;h=d121cb9e2e5fc42466aeb0f68fd42bdb5f9daf61;hb=9d1bfb34842de4a129140622ee3d800297c0e69d;hp=9d3c392659753043667af822b9bbfe7bd3e1b0f0;hpb=a70c4580757c19cd5054a470c2c5d497a1e71b4c;p=pspp diff --git a/src/libpspp/temp-file.c b/src/libpspp/temp-file.c index 9d3c392659..d121cb9e2e 100644 --- a/src/libpspp/temp-file.c +++ b/src/libpspp/temp-file.c @@ -40,6 +40,7 @@ */ +static void cleanup (void); static struct temp_dir *temp_dir; struct hmapx map; @@ -51,6 +52,30 @@ setup (void) 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) { @@ -74,13 +99,9 @@ create_temp_file (void) char *file_name; FILE *stream; + initialise (); 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);