Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/core/StarFile_unix.cpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 20:23:44 +1000
committerKae <80987908+Novaenia@users.noreply.github.com>2023-06-27 20:23:44 +1000
commit332983c97b7a729c4dc5f19aa9ee4a22c420f7d8 (patch)
treefd9c441b796b522bdd5c7f8fbd32f51b8eff2a28 /source/core/StarFile_unix.cpp
parent14b9689b6d4f4ad5276c88130dc6e449bedc0709 (diff)
The Formatting String Catastrophe
Diffstat (limited to 'source/core/StarFile_unix.cpp')
-rw-r--r--source/core/StarFile_unix.cpp34
1 files changed, 17 insertions, 17 deletions
diff --git a/source/core/StarFile_unix.cpp b/source/core/StarFile_unix.cpp
index aa22bc8..abc9fe0 100644
--- a/source/core/StarFile_unix.cpp
+++ b/source/core/StarFile_unix.cpp
@@ -46,19 +46,19 @@ String File::currentDirectory() {
void File::changeDirectory(const String& dirName) {
if (::chdir(dirName.utf8Ptr()) != 0)
- throw IOException(strf("could not change directory to %s", dirName));
+ throw IOException(strf("could not change directory to {}", dirName));
}
void File::makeDirectory(String const& dirName) {
if (::mkdir(dirName.utf8Ptr(), 0777) != 0)
- throw IOException(strf("could not create directory '%s', %s", dirName, strerror(errno)));
+ throw IOException(strf("could not create directory '{}', {}", dirName, strerror(errno)));
}
List<pair<String, bool>> File::dirList(const String& dirName, bool skipDots) {
List<std::pair<String, bool>> fileList;
DIR* directory = ::opendir(dirName.utf8Ptr());
if (directory == NULL)
- throw IOException::format("dirList failed on dir: '%s'", dirName);
+ throw IOException::format("dirList failed on dir: '{}'", dirName);
for (dirent* entry = ::readdir(directory); entry != NULL; entry = ::readdir(directory)) {
String entryString = entry->d_name;
@@ -113,13 +113,13 @@ String File::fullPath(const String& fileName) {
char buffer[PATH_MAX];
if (::realpath(fileName.utf8Ptr(), buffer) == NULL)
- throw IOException::format("realpath failed on file: '%s' problem path was: '%s'", fileName, buffer);
+ throw IOException::format("realpath failed on file: '{}' problem path was: '{}'", fileName, buffer);
return String(buffer);
}
String File::temporaryFileName() {
- return relativeTo(P_tmpdir, strf("starbound.tmpfile.%s", hexEncode(Random::randBytes(16))));
+ return relativeTo(P_tmpdir, strf("starbound.tmpfile.{}", hexEncode(Random::randBytes(16))));
}
FilePtr File::temporaryFile() {
@@ -131,16 +131,16 @@ FilePtr File::ephemeralFile() {
ByteArray path = ByteArray::fromCStringWithNull(relativeTo(P_tmpdir, "starbound.tmpfile.XXXXXXXX").utf8Ptr());
auto res = mkstemp(path.ptr());
if (res < 0)
- throw IOException::format("tmpfile error: %s", strerror(errno));
+ throw IOException::format("tmpfile error: {}", strerror(errno));
if (::unlink(path.ptr()) < 0)
- throw IOException::format("Could not remove mkstemp file when creating ephemeralFile: %s", strerror(errno));
+ throw IOException::format("Could not remove mkstemp file when creating ephemeralFile: {}", strerror(errno));
file->m_file = handleFromFd(res);
file->setMode(IOMode::ReadWrite);
return file;
}
String File::temporaryDirectory() {
- String dirname = relativeTo(P_tmpdir, strf("starbound.tmpdir.%s", hexEncode(Random::randBytes(16))));
+ String dirname = relativeTo(P_tmpdir, strf("starbound.tmpdir.{}", hexEncode(Random::randBytes(16))));
makeDirectory(dirname);
return dirname;
}
@@ -171,12 +171,12 @@ bool File::isDirectory(String const& path) {
void File::remove(String const& filename) {
if (::remove(filename.utf8Ptr()) < 0)
- throw IOException::format("remove error: %s", strerror(errno));
+ throw IOException::format("remove error: {}", strerror(errno));
}
void File::rename(String const& source, String const& target) {
if (::rename(source.utf8Ptr(), target.utf8Ptr()) < 0)
- throw IOException::format("rename error: %s", strerror(errno));
+ throw IOException::format("rename error: {}", strerror(errno));
}
void File::overwriteFileWithRename(char const* data, size_t len, String const& filename, String const& newSuffix) {
@@ -200,11 +200,11 @@ void* File::fopen(char const* filename, IOMode mode) {
int fd = ::open(filename, oflag, 0666);
if (fd < 0)
- throw IOException::format("Error opening file '%s', error: %s", filename, strerror(errno));
+ throw IOException::format("Error opening file '{}', error: {}", filename, strerror(errno));
if (mode & IOMode::Append) {
if (lseek(fd, 0, SEEK_END) < 0)
- throw IOException::format("Error opening file '%s', cannot seek: %s", filename, strerror(errno));
+ throw IOException::format("Error opening file '{}', cannot seek: {}", filename, strerror(errno));
}
return handleFromFd(fd);
@@ -221,7 +221,7 @@ void File::fseek(void* f, StreamOffset offset, IOSeek seekMode) {
retCode = lseek(fd, offset, SEEK_END);
if (retCode < 0)
- throw IOException::format("Seek error: %s", strerror(errno));
+ throw IOException::format("Seek error: {}", strerror(errno));
}
StreamOffset File::ftell(void* f) {
@@ -237,7 +237,7 @@ size_t File::fread(void* file, char* data, size_t len) {
if (ret < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;
- throw IOException::format("Read error: %s", strerror(errno));
+ throw IOException::format("Read error: {}", strerror(errno));
} else {
return ret;
}
@@ -252,7 +252,7 @@ size_t File::fwrite(void* file, char const* data, size_t len) {
if (ret < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;
- throw IOException::format("Write error: %s", strerror(errno));
+ throw IOException::format("Write error: {}", strerror(errno));
} else {
return ret;
}
@@ -269,7 +269,7 @@ void File::fsync(void* file) {
void File::fclose(void* file) {
if (::close(fdFromHandle(file)) < 0)
- throw IOException::format("Close error: %s", strerror(errno));
+ throw IOException::format("Close error: {}", strerror(errno));
}
StreamOffset File::fsize(void* file) {
@@ -289,7 +289,7 @@ size_t File::pwrite(void* file, char const* data, size_t len, StreamOffset posit
void File::resize(void* f, StreamOffset size) {
if (::ftruncate(fdFromHandle(f), size) < 0)
- throw IOException::format("resize error: %s", strerror(errno));
+ throw IOException::format("resize error: {}", strerror(errno));
}
}