1 /* PSPP - computes sample statistics.
2 Copyright (C) 2004 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
31 #define _(msgid) gettext (msgid)
33 /* Creates a temporary file and stores its name in *FILENAME and
34 a file descriptor for it in *FD. Returns success. Caller is
35 responsible for freeing *FILENAME. */
37 make_temp_file (int *fd, char **filename)
39 const char *parent_dir;
41 assert (filename != NULL);
44 if (getenv ("TMPDIR") != NULL)
45 parent_dir = getenv ("TMPDIR");
47 parent_dir = P_tmpdir;
49 *filename = xmalloc (strlen (parent_dir) + 32);
50 sprintf (*filename, "%s%cpsppXXXXXX", parent_dir, DIR_SEPARATOR);
51 *fd = mkstemp (*filename);
54 msg (FE, _("%s: Creating temporary file: %s."),
55 *filename, strerror (errno));
64 /* Creates a temporary file and stores its name in *FILENAME and
65 a file stream for it in *FP. Returns success. Caller is
66 responsible for freeing *FILENAME and for closing *FP */
68 make_unique_file_stream (FILE **fp, char **filename)
70 static int serial = 0;
71 const char *parent_dir;
75 Need to check for pre-existing file name.
76 Need also to pass in the directory instead of using /tmp
79 assert (filename != NULL);
82 if (getenv ("TMPDIR") != NULL)
83 parent_dir = getenv ("TMPDIR");
85 parent_dir = P_tmpdir;
87 *filename = xmalloc (strlen (parent_dir) + 32);
90 sprintf (*filename, "%s%cpspp%d.png", parent_dir, DIR_SEPARATOR, serial++);
92 *fp = fopen(*filename, "w");
96 msg (FE, _("%s: Creating file: %s."), *filename, strerror (errno));