aboutsummaryrefslogtreecommitdiff
path: root/src/util/disk.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2009-07-27 20:07:24 +0000
committerChristian Grothoff <christian@grothoff.org>2009-07-27 20:07:24 +0000
commitfe9ed98ff54df7d65dd0a0f787c86a734ef4d1a4 (patch)
tree81738f3a8a167533ddf001a72809dfa5015186de /src/util/disk.c
parentc5cda378386d01412ada7fbf8d51317bab1ab695 (diff)
downloadgnunet-fe9ed98ff54df7d65dd0a0f787c86a734ef4d1a4.tar.gz
gnunet-fe9ed98ff54df7d65dd0a0f787c86a734ef4d1a4.zip
mktemp
Diffstat (limited to 'src/util/disk.c')
-rw-r--r--src/util/disk.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/util/disk.c b/src/util/disk.c
index 857370c5b..738839807 100644
--- a/src/util/disk.c
+++ b/src/util/disk.c
@@ -194,6 +194,52 @@ GNUNET_DISK_file_size (const char *filename,
194 194
195 195
196/** 196/**
197 * Create an (empty) temporary file on disk.
198 *
199 * @param template component to use for the name;
200 * does NOT contain "XXXXXX" or "/tmp/".
201 * @return NULL on error, otherwise name of fresh
202 * file on disk in directory for temporary files
203 */
204char *
205GNUNET_DISK_mktemp (const char *template)
206{
207 const char *tmpdir;
208 int fd;
209 char *tmpl;
210 char *fn;
211
212 tmpdir = getenv ("TMPDIR");
213 tmpdir = tmpdir ? tmpdir : "/tmp";
214
215 GNUNET_asprintf (&tmpl,
216 "%s%s%s%s",
217 tmpdir,
218 DIR_SEPARATOR_STR,
219 template,
220 "XXXXXX");
221#ifdef MINGW
222 fn = (char *) GNUNET_malloc (MAX_PATH + 1);
223 plibc_conv_to_win_path (tmpl, fn);
224 GNUNET_free (tmpl);
225#else
226 fn = tmpl;
227#endif
228 fd = mkstemp (fn);
229 if (fd == -1)
230 {
231 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
232 "mkstemp",
233 fn);
234 GNUNET_free (fn);
235 return NULL;
236 }
237 CLOSE (fd);
238 return fn;
239}
240
241
242/**
197 * Get the number of blocks that are left on the partition that 243 * Get the number of blocks that are left on the partition that
198 * contains the given file (for normal users). 244 * contains the given file (for normal users).
199 * 245 *