Skip to content

Commit 88309fc

Browse files
committed
Minor changes
1 parent 2796f80 commit 88309fc

File tree

5 files changed

+58
-53
lines changed

5 files changed

+58
-53
lines changed

Sources/Shared/Containers/StringConcatenable.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,19 @@ namespace Death { namespace Containers {
146146
typedef String ConvertTo;
147147

148148
static std::size_t size(const char a[N]) {
149-
return strnlen(a, N);
149+
for (std::size_t i = 0; i < N; i++) {
150+
if (a[i] == '\0') {
151+
return i;
152+
}
153+
}
154+
return N;
150155
}
151156
static inline void appendTo(const char a[N], char*& out) {
152-
while (*a != '\0') {
153-
*out++ = *a++;
157+
for (std::size_t i = 0; i < N; i++) {
158+
if (a[i] == '\0') {
159+
break;
160+
}
161+
*out++ = a[i];
154162
}
155163
}
156164
};

Sources/Shared/IO/FileStream.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
# include <cerrno>
1818
# include <fcntl.h>
1919
# include <sys/stat.h>
20-
# include <sys/unistd.h>
2120
# include <unistd.h>
2221
#endif
2322

Sources/Shared/IO/FileSystem.cpp

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@
2222
# include <cerrno>
2323
# include <cstdio>
2424
# include <cstring>
25-
# include <ctime>
26-
# include <unistd.h>
27-
# include <sys/stat.h>
28-
# include <libgen.h>
29-
# include <pwd.h>
3025
# include <dirent.h>
3126
# include <fcntl.h>
3227
# include <ftw.h>
28+
# include <libgen.h>
29+
# include <pwd.h>
30+
# include <strings.h>
31+
# include <sys/stat.h>
32+
# include <unistd.h>
3333
# if defined(DEATH_TARGET_ANDROID) || defined(DEATH_TARGET_APPLE) || defined(DEATH_TARGET_UNIX)
3434
# include <sys/mman.h>
3535
# endif
@@ -48,12 +48,11 @@
4848
# include <mach-o/dyld.h>
4949
# elif defined(DEATH_TARGET_EMSCRIPTEN)
5050
# include <emscripten/emscripten.h>
51-
# elif defined(__linux__)
52-
# include <sys/sendfile.h>
53-
# endif
54-
# if defined(__FreeBSD__)
51+
# elif defined(__FreeBSD__)
5552
# include <sys/types.h>
5653
# include <sys/sysctl.h>
54+
# elif defined(__linux__)
55+
# include <sys/sendfile.h>
5756
# endif
5857
#endif
5958

@@ -280,8 +279,8 @@ namespace Death { namespace IO {
280279

281280
static bool DeleteDirectoryInternal(StringView path)
282281
{
283-
# if defined(DEATH_TARGET_SWITCH)
284-
// nftw() is missing in libnx
282+
# if defined(DEATH_TARGET_SWITCH) || defined(DEATH_TARGET_VITA)
283+
// nftw() is missing in libnx and Vita
285284
auto nullTerminatedPath = String::nullTerminatedView(path);
286285
DIR* d = ::opendir(nullTerminatedPath.data());
287286
std::int32_t r = -1;
@@ -591,17 +590,26 @@ namespace Death { namespace IO {
591590
goto Retry;
592591
}
593592

593+
# if defined(DEATH_TARGET_VITA)
594+
if ((_options & EnumerationOptions::SkipDirectories) == EnumerationOptions::SkipDirectories && SCE_S_ISDIR(entry->d_stat.st_attr))
595+
goto Retry;
596+
if ((_options & EnumerationOptions::SkipFiles) == EnumerationOptions::SkipFiles && SCE_S_ISREG(entry->d_stat.st_attr))
597+
goto Retry;
598+
if ((_options & EnumerationOptions::SkipSpecial) == EnumerationOptions::SkipSpecial && !SCE_S_ISDIR(entry->d_stat.st_attr) && !SCE_S_ISREG(entry->d_stat.st_attr) && !SCE_S_ISLNK(entry->d_stat.st_attr))
599+
goto Retry;
600+
# else
594601
if ((_options & EnumerationOptions::SkipDirectories) == EnumerationOptions::SkipDirectories && entry->d_type == DT_DIR)
595602
goto Retry;
596-
# if !defined(DEATH_TARGET_EMSCRIPTEN)
603+
# if !defined(DEATH_TARGET_EMSCRIPTEN)
597604
if ((_options & EnumerationOptions::SkipFiles) == EnumerationOptions::SkipFiles && entry->d_type == DT_REG)
598605
goto Retry;
599606
if ((_options & EnumerationOptions::SkipSpecial) == EnumerationOptions::SkipSpecial && entry->d_type != DT_DIR && entry->d_type != DT_REG && entry->d_type != DT_LNK)
600607
goto Retry;
601-
# else
608+
# else
602609
// Emscripten doesn't set DT_REG for files, so we treat everything that's not a DT_DIR as a file. SkipSpecial has no effect here.
603610
if ((_options & EnumerationOptions::SkipFiles) == EnumerationOptions::SkipFiles && entry->d_type != DT_DIR)
604611
goto Retry;
612+
# endif
605613
# endif
606614
std::size_t charsLeft = sizeof(_path) - (_fileNamePart - _path) - 1;
607615
# if defined(__FreeBSD__)
@@ -1039,13 +1047,13 @@ namespace Death { namespace IO {
10391047
}
10401048

10411049
return Utf8::FromUtf16(buffer, length);
1042-
#elif defined(DEATH_TARGET_SWITCH)
1043-
// realpath() is missing in libnx
1050+
#elif defined(DEATH_TARGET_SWITCH) || defined(DEATH_TARGET_VITA)
1051+
// realpath() is missing in libnx and Vita
10441052
char left[MaxPathLength];
10451053
char nextToken[MaxPathLength];
10461054
char result[MaxPathLength];
10471055
std::size_t resultLength = 0;
1048-
# if !defined(DEATH_TARGET_SWITCH)
1056+
# if !defined(DEATH_TARGET_SWITCH) && !defined(DEATH_TARGET_VITA)
10491057
std::int32_t symlinks = 0;
10501058
# endif
10511059

@@ -1119,8 +1127,8 @@ namespace Death { namespace IO {
11191127
}
11201128
return {};
11211129
}
1122-
# if !defined(DEATH_TARGET_SWITCH)
1123-
// readlink() is missing in libnx
1130+
# if !defined(DEATH_TARGET_SWITCH) && !defined(DEATH_TARGET_VITA)
1131+
// readlink() is missing in libnx and Vita
11241132
if (S_ISLNK(sb.st_mode)) {
11251133
if (++symlinks > 8) {
11261134
// Too many symlinks
@@ -1254,7 +1262,7 @@ namespace Death { namespace IO {
12541262
}
12551263

12561264
return CombinePath({ home, "Library/Application Support"_s, applicationName });
1257-
#elif defined(DEATH_TARGET_UNIX) || defined(DEATH_TARGET_EMSCRIPTEN)
1265+
#elif defined(DEATH_TARGET_UNIX) || defined(DEATH_TARGET_EMSCRIPTEN) || defined(DEATH_TARGET_VITA)
12581266
StringView config = ::getenv("XDG_CONFIG_HOME");
12591267
if (IsAbsolutePath(config)) {
12601268
return CombinePath(config, applicationName);
@@ -1355,8 +1363,8 @@ namespace Death { namespace IO {
13551363
if (!home.empty()) {
13561364
return home;
13571365
}
1358-
# if !defined(DEATH_TARGET_EMSCRIPTEN)
1359-
// `getpwuid()` is not yet implemented on Emscripten
1366+
# if !defined(DEATH_TARGET_EMSCRIPTEN) && !defined(DEATH_TARGET_VITA)
1367+
// `getpwuid()` is not implemented on Emscripten and Vita
13601368
const struct passwd* pw = ::getpwuid(getuid());
13611369
if (pw != nullptr) {
13621370
return pw->pw_dir;
@@ -2175,8 +2183,15 @@ namespace Death { namespace IO {
21752183
return false;
21762184
}
21772185

2186+
# if defined(DEATH_TARGET_VITA)
2187+
// O_CLOEXEC is not supported on Vita
2188+
const std::int32_t commonFlags = 0;
2189+
# else
2190+
const std::int32_t commonFlags = O_CLOEXEC;
2191+
# endif
2192+
21782193
std::int32_t sourceFd, destFd;
2179-
if ((sourceFd = ::open(nullTerminatedOldPath.data(), O_RDONLY | O_CLOEXEC)) == -1) {
2194+
if ((sourceFd = ::open(nullTerminatedOldPath.data(), O_RDONLY | commonFlags)) == -1) {
21802195
return false;
21812196
}
21822197

@@ -2191,12 +2206,12 @@ namespace Death { namespace IO {
21912206
// Enable writing for the newly created files, needed for some file systems
21922207
destMode |= S_IWUSR;
21932208
#endif
2194-
if ((destFd = ::open(nullTerminatedNewPath.data(), O_WRONLY | O_CLOEXEC | O_CREAT | O_TRUNC, destMode)) == -1) {
2209+
if ((destFd = ::open(nullTerminatedNewPath.data(), O_WRONLY | O_CREAT | O_TRUNC | commonFlags, destMode)) == -1) {
21952210
::close(sourceFd);
21962211
return false;
21972212
}
21982213

2199-
#if !defined(DEATH_TARGET_APPLE) && !defined(DEATH_TARGET_SWITCH) && !defined(__FreeBSD__)
2214+
#if !defined(DEATH_TARGET_APPLE) && !defined(DEATH_TARGET_SWITCH) && !defined(DEATH_TARGET_VITA) && !defined(__FreeBSD__)
22002215
while (true) {
22012216
if (::fallocate(destFd, FALLOC_FL_KEEP_SIZE, 0, sb.st_size) == 0) {
22022217
break;

Sources/Shared/IO/FileSystem.h

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,6 @@
77
#include <memory>
88
#include <optional>
99

10-
#if !defined(DEATH_TARGET_WINDOWS) && !defined(DOXYGEN_GENERATING_OUTPUT)
11-
# include <climits> // for `PATH_MAX`
12-
# if defined(DEATH_TARGET_APPLE) || defined(DEATH_TARGET_SWITCH)
13-
# include <dirent.h>
14-
# elif defined(DEATH_TARGET_ANDROID)
15-
using DIR = struct DIR;
16-
using AAssetDir = struct AAssetDir;
17-
# elif defined(__FreeBSD__)
18-
struct _dirdesc;
19-
using DIR = struct _dirdesc;
20-
# else
21-
struct __dirstream;
22-
using DIR = struct __dirstream;
23-
# endif
24-
#endif
25-
2610
namespace Death { namespace IO {
2711
//###==##====#=====--==~--~=~- --- -- - - - -
2812

@@ -34,15 +18,14 @@ namespace Death { namespace IO {
3418
public:
3519
/** @{ @name Constants */
3620

37-
#if defined(DEATH_TARGET_WINDOWS)
38-
// Windows 10 supports long paths everywhere, so increase it a bit
21+
// Windows 10 supports long paths everywhere and Unix systems usually also support at least 2048 characters
3922
/** @brief Maximum path length supported */
40-
static constexpr std::size_t MaxPathLength = /*MAX_PATH*/2048;
23+
static constexpr std::size_t MaxPathLength = 2048;
24+
25+
#if defined(DEATH_TARGET_WINDOWS)
4126
/** @brief Native path separator */
4227
static constexpr char PathSeparator[] = "\\";
4328
#else
44-
/** @brief Maximum path length supported */
45-
static constexpr std::size_t MaxPathLength = PATH_MAX;
4629
/** @brief Native path separator */
4730
static constexpr char PathSeparator[] = "/";
4831
#endif

Sources/nCine/I18n.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -665,11 +665,11 @@ namespace nCine
665665
}
666666
#elif defined(DEATH_TARGET_EMSCRIPTEN) || defined(DEATH_TARGET_UNIX)
667667
char* langRaw = ::getenv("LANG");
668-
if (langRaw == nullptr || langRaw[0] == '\0' || strcasecmp(langRaw, "C") == 0) {
668+
if (langRaw == nullptr || langRaw[0] == '\0' || ::strcasecmp(langRaw, "C") == 0) {
669669
langRaw = ::getenv("LC_ALL");
670-
if (langRaw == nullptr || langRaw[0] == '\0' || strcasecmp(langRaw, "C") == 0) {
670+
if (langRaw == nullptr || langRaw[0] == '\0' || ::strcasecmp(langRaw, "C") == 0) {
671671
langRaw = ::getenv("LC_MESSAGES");
672-
if (langRaw == nullptr || langRaw[0] == '\0' || strcasecmp(langRaw, "C") == 0) {
672+
if (langRaw == nullptr || langRaw[0] == '\0' || ::strcasecmp(langRaw, "C") == 0) {
673673
// No suitable environment variable is defined
674674
return preferred;
675675
}
@@ -681,7 +681,7 @@ namespace nCine
681681
if (suffix != nullptr) {
682682
langId = langId.prefix(suffix.begin());
683683
}
684-
if (strcasecmp(langId.data(), "C") != 0) {
684+
if (::strcasecmp(langId.data(), "C") != 0) {
685685
StringUtils::replaceAllInPlace(langId, '_', '-');
686686
StringUtils::lowercaseInPlace(langId);
687687
arrayAppend(preferred, std::move(langId));

0 commit comments

Comments
 (0)