Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame^] | 1 | // |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 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) |
Rob Hughes | bc873d2 | 2020-05-20 13:11:37 +0100 | [diff] [blame] | 12 | #include "WindowsWrapper.hpp" |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 13 | #endif |
| 14 | |
| 15 | namespace armnnUtils |
| 16 | { |
| 17 | namespace Filesystem |
| 18 | { |
| 19 | |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 20 | long long GetFileSize(const char* path) |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 21 | { |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 22 | #if defined(__ANDROID__) |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 23 | struct stat statusBuffer; |
| 24 | if (stat(path, & statusBuffer) != 0) |
| 25 | { |
| 26 | return -1; |
| 27 | } |
| 28 | return statusBuffer.st_size; |
David Monahan | a0d1896 | 2020-01-24 09:13:33 +0000 | [diff] [blame] | 29 | #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 Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 36 | #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 | |
| 46 | bool 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 | } |