aboutsummaryrefslogtreecommitdiff
path: root/src/armnnUtils/Filesystem.cpp
blob: 6c8175b2024795d94819958e400dd15874fceb01 (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
56
57
//
// Copyright © 2020 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//

#include "Filesystem.hpp"

#if defined(__unix__)
#include <sys/stat.h>
#include <stdio.h>
#elif defined(_MSC_VER)
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#endif

namespace armnnUtils
{
namespace Filesystem
{

long long GetFileSize(const char* path)
{
#if defined(__ANDROID__)
    struct stat statusBuffer;
    if (stat(path, & statusBuffer) != 0)
    {
        return -1;
    }
    return statusBuffer.st_size;
#elif defined(__unix__)
    struct stat statusBuffer;
    if (stat(path, & statusBuffer) != 0)
    {
        return -1;
    }
    return static_cast<long long>(statusBuffer.st_size);
#elif defined(_MSC_VER)
    WIN32_FILE_ATTRIBUTE_DATA attr;
    if (::GetFileAttributesEx(path, GetFileExInfoStandard, &attr) == 0)
    {
        return -1;
    }
    return attr.nFileSizeLow;
#endif
}

bool Remove(const char* path)
{
#if defined(__unix__)
    return remove(path) == 0;
#elif defined(_MSC_VER)
    return ::DeleteFile(path);
#endif
}

}
}