lfilesystem  0.0.1
C++ filesystem library
lfilesystem_Misc.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #if defined(_WIN32) || defined(WIN32)
18 # include <windows.h>
19 #elif __has_include(<linux/limits.h>)
20 # include <linux/limits.h>
21 #else
22 # include <climits>
23 #endif
24 
25 #include "lfilesystem/lfilesystem_Export.h"
26 #include <cstdint>
27 #include <filesystem>
28 
35 namespace limes::files
36 {
37 
43 [[nodiscard]] LFILE_EXPORT constexpr char dirSeparator() noexcept
44 {
45  return static_cast<char> (std::filesystem::path::preferred_separator);
46 }
47 
52 [[nodiscard]] LFILE_EXPORT consteval char PATHseparator() noexcept
53 {
54 #if defined(_WIN32) || defined(WIN32)
55  return ';';
56 #else
57  return ':';
58 #endif
59 }
60 
69 [[nodiscard]] LFILE_EXPORT consteval bool filesystemIsCaseSensitive() noexcept
70 {
71 #if defined(__linux__) || defined(__gnu_linux__) || defined(linux) || defined(__linux)
72  return true;
73 #else
74  return false;
75 #endif
76 }
77 
83 [[nodiscard]] LFILE_EXPORT constexpr std::uintmax_t maxPathLength() noexcept
84 {
85 #if defined(_WIN32) || defined(WIN32)
86  return static_cast<std::uintmax_t> (MAX_PATH);
87 #elif defined(NAME_MAX)
88  return static_cast<std::uintmax_t> (NAME_MAX);
89 #elif defined(PATH_MAX)
90  return static_cast<std::uintmax_t> (PATH_MAX);
91 #elif defined(FILENAME_MAX)
92  return static_cast<std::uintmax_t> (FILENAME_MAX);
93 #else
94 # error "Cannot detect maximum path length for your platform!"
95 #endif
96 }
97 
100 } // namespace files
LFILE_EXPORT consteval bool filesystemIsCaseSensitive() noexcept
Returns true if the current platform's filesystem is likely to be case-sensitive.
constexpr LFILE_EXPORT char dirSeparator() noexcept
Returns the platform's preferred directory separator: \ on Windows, and / everywhere else.
LFILE_EXPORT consteval char PATHseparator() noexcept
Returns the platform's separator char for the PATH environment variable: ; on Windows,...
constexpr LFILE_EXPORT std::uintmax_t maxPathLength() noexcept
Returns the maximum path length possible on the current operating system.
Filesystem utilities.