diff options
author | Rob Hughes <robert.hughes@arm.com> | 2020-01-07 17:05:24 +0000 |
---|---|---|
committer | Rob Hughes <robert.hughes@arm.com> | 2020-01-21 16:01:58 +0000 |
commit | bdee4267583a7daaf9ea5284d2ff6d4bbb782229 (patch) | |
tree | f61b4fd91777509fc8d55a23fd25af5e8f15ceb8 /src/armnnUtils | |
parent | 25b7436b02514145a0289daff78f5b9f64cdd0db (diff) | |
download | armnn-bdee4267583a7daaf9ea5284d2ff6d4bbb782229.tar.gz |
Add thin abstraction layer for processes and filesystem
This is used instead of some hardcoded Unix calls and means this code
now works on Windows
(This is a rework of a previous patch which used boost, now that I have
been informed that we are trying to move towards removing boost).
Change-Id: Ib0d11055279bbd7b710f086e9890369e3ecbfe9a
Signed-off-by: Robert Hughes <robert.hughes@arm.com>
Diffstat (limited to 'src/armnnUtils')
-rw-r--r-- | src/armnnUtils/Filesystem.cpp | 50 | ||||
-rw-r--r-- | src/armnnUtils/Filesystem.hpp | 18 | ||||
-rw-r--r-- | src/armnnUtils/Processes.cpp | 30 | ||||
-rw-r--r-- | src/armnnUtils/Processes.hpp | 16 |
4 files changed, 114 insertions, 0 deletions
diff --git a/src/armnnUtils/Filesystem.cpp b/src/armnnUtils/Filesystem.cpp new file mode 100644 index 0000000000..08c447b3f6 --- /dev/null +++ b/src/armnnUtils/Filesystem.cpp @@ -0,0 +1,50 @@ +// +// 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 GetFileSize(const char* path) +{ +#if defined(__unix__) + struct stat statusBuffer; + if (stat(path, & statusBuffer) != 0) + { + return -1; + } + return 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 +} + +} +} diff --git a/src/armnnUtils/Filesystem.hpp b/src/armnnUtils/Filesystem.hpp new file mode 100644 index 0000000000..d6dc5b97fd --- /dev/null +++ b/src/armnnUtils/Filesystem.hpp @@ -0,0 +1,18 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +namespace armnnUtils +{ +namespace Filesystem +{ + +long GetFileSize(const char* path); + +bool Remove(const char* path); + +} +} diff --git a/src/armnnUtils/Processes.cpp b/src/armnnUtils/Processes.cpp new file mode 100644 index 0000000000..0e43e8cecd --- /dev/null +++ b/src/armnnUtils/Processes.cpp @@ -0,0 +1,30 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "Processes.hpp" + +#if defined(__unix__) +#include <unistd.h> +#elif defined(_MSC_VER) +#define WIN32_LEAN_AND_MEAN +#include <Windows.h> +#endif + +namespace armnnUtils +{ +namespace Processes +{ + +int GetCurrentId() +{ +#if defined(__unix__) + return getpid(); +#elif defined(_MSC_VER) + return ::GetCurrentProcessId(); +#endif +} + +} +} diff --git a/src/armnnUtils/Processes.hpp b/src/armnnUtils/Processes.hpp new file mode 100644 index 0000000000..0f1d955bb1 --- /dev/null +++ b/src/armnnUtils/Processes.hpp @@ -0,0 +1,16 @@ +// +// Copyright © 2020 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +namespace armnnUtils +{ +namespace Processes +{ + +int GetCurrentId(); + +} +} |