blob: 4a2e2ed3934d4c8ac75efe9558c909d6d34fb403 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Rob Hughesbdee4262020-01-07 17:05:24 +00002// Copyright © 2020 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "Filesystem.hpp"
7
8#if defined(__unix__)
9#include <sys/stat.h>
10#include <stdio.h>
11#elif defined(_MSC_VER)
Rob Hughesbc873d22020-05-20 13:11:37 +010012#include "WindowsWrapper.hpp"
Rob Hughesbdee4262020-01-07 17:05:24 +000013#endif
14
15namespace armnnUtils
16{
17namespace Filesystem
18{
19
David Monahana0d18962020-01-24 09:13:33 +000020long long GetFileSize(const char* path)
Rob Hughesbdee4262020-01-07 17:05:24 +000021{
David Monahana0d18962020-01-24 09:13:33 +000022#if defined(__ANDROID__)
Rob Hughesbdee4262020-01-07 17:05:24 +000023 struct stat statusBuffer;
24 if (stat(path, & statusBuffer) != 0)
25 {
26 return -1;
27 }
28 return statusBuffer.st_size;
David Monahana0d18962020-01-24 09:13:33 +000029#elif defined(__unix__)
30 struct stat statusBuffer;
31 if (stat(path, & statusBuffer) != 0)
32 {
33 return -1;
34 }
35 return static_cast<long long>(statusBuffer.st_size);
Rob Hughesbdee4262020-01-07 17:05:24 +000036#elif defined(_MSC_VER)
37 WIN32_FILE_ATTRIBUTE_DATA attr;
38 if (::GetFileAttributesEx(path, GetFileExInfoStandard, &attr) == 0)
39 {
40 return -1;
41 }
42 return attr.nFileSizeLow;
43#endif
44}
45
46bool Remove(const char* path)
47{
48#if defined(__unix__)
49 return remove(path) == 0;
50#elif defined(_MSC_VER)
51 return ::DeleteFile(path);
52#endif
53}
54
55}
56}