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
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 ;
0 commit comments