summaryrefslogtreecommitdiff
path: root/pith/osdep/tempfile.c
blob: 535eea821d3c3a7725260097c18c8bc3d12faf18 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#if !defined(lint) && !defined(DOS)
static char rcsid[] = "$Id: tempfile.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
#endif

/*
 * ========================================================================
 * Copyright 2006-2008 University of Washington
 * Copyright 2013-2015 Eduardo Chappa
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * ========================================================================
 */

#include <system.h>

#if	HAVE_TMPFILE
#else
#include "temp_nam.h"
#endif

#include "../charconv/filesys.h"

#include "tempfile.h"


/*----------------------------------------------------------------------
   Create a temporary file, the name of which we don't care about 
and that goes away when it is closed.  Just like ANSI C tmpfile.
  ----*/
FILE  *
create_tmpfile(void)
{
#if	HAVE_TMPFILE
    return(tmpfile());
#else
    char *file_name;
    FILE *stream = NULL;

    file_name = temp_nam(NULL, "pine-tmp");
    if(file_name){
	stream = our_fopen(file_name, "w+b");
	our_unlink(file_name);
	fs_give((void **) &file_name);
    }

    return(stream);
#endif
}