summaryrefslogtreecommitdiff
path: root/AK/TemporaryFile.cpp
blob: 3ed991c01fff4b64447634751e6070c354a82079 (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
#include "TemporaryFile.h"
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

namespace AK {

TemporaryFile::TemporaryFile()
{
    char nameBuffer[] = "/tmp/AKTemporaryFile.XXXXXX";
    int fd = mkstemp(nameBuffer);
    if (fd != -1) {
        m_stream = fdopen(fd, "w+");
        m_file_name = nameBuffer;
    }
}

TemporaryFile::~TemporaryFile()
{
    if (is_valid()) {
        unlink(m_file_name.characters());
        fclose(m_stream);
    }
}

void TemporaryFile::sync()
{
    if (m_stream)
        fflush(m_stream);
}

}