Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 1 | // |
| 2 | // 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) |
| 12 | #define WIN32_LEAN_AND_MEAN |
| 13 | #include <Windows.h> |
| 14 | #endif |
| 15 | |
| 16 | namespace armnnUtils |
| 17 | { |
| 18 | namespace Filesystem |
| 19 | { |
| 20 | |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 21 | long long GetFileSize(const char* path) |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 22 | { |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 23 | #if defined(__ANDROID__) |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 24 | struct stat statusBuffer; |
| 25 | if (stat(path, & statusBuffer) != 0) |
| 26 | { |
| 27 | return -1; |
| 28 | } |
| 29 | return statusBuffer.st_size; |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 30 | #elif defined(__unix__) |
| 31 | struct stat statusBuffer; |
| 32 | if (stat(path, & statusBuffer) != 0) |
| 33 | { |
| 34 | return -1; |
| 35 | } |
| 36 | return static_cast<long long>(statusBuffer.st_size); |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 37 | #elif defined(_MSC_VER) |
| 38 | WIN32_FILE_ATTRIBUTE_DATA attr; |
| 39 | if (::GetFileAttributesEx(path, GetFileExInfoStandard, &attr) == 0) |
| 40 | { |
| 41 | return -1; |
| 42 | } |
| 43 | return attr.nFileSizeLow; |
| 44 | #endif |
| 45 | } |
| 46 | |
| 47 | bool Remove(const char* path) |
| 48 | { |
| 49 | #if defined(__unix__) |
| 50 | return remove(path) == 0; |
| 51 | #elif defined(_MSC_VER) |
| 52 | return ::DeleteFile(path); |
| 53 | #endif |
| 54 | } |
| 55 | |
| 56 | } |
| 57 | } |