1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-30 02:05:13 +01:00

Minor fixes, mostly posix.c

This commit is contained in:
Michał Janiszewski
2016-01-15 08:20:12 +01:00
parent cee61f8929
commit 5bc330f8db
3 changed files with 11 additions and 10 deletions

View File

@@ -132,7 +132,7 @@ exitcode_t CommandLine::HandleCommandDefault()
if (_openrctDataPath != NULL) {
String::Set(gCustomOpenrctDataPath, sizeof(gCustomOpenrctDataPath), _openrctDataPath);
Memory::Free(gCustomOpenrctDataPath);
Memory::Free(_openrctDataPath);
}
return result;

View File

@@ -192,7 +192,10 @@ bool platform_directory_delete(const utf8 *path)
chp = fts_children(ftsp, 0);
if (chp == NULL) {
log_verbose("No files to traverse, deleting directory %s", path);
remove(path);
if (remove(path) != 0)
{
log_error("Failed to remove %s, errno = %d", path, errno);
}
free(ourPath);
return true; // No files to traverse
}
@@ -227,12 +230,9 @@ bool platform_directory_delete(const utf8 *path)
bool platform_lock_single_instance()
{
char pidFilePath[MAX_PATH];
char separator = platform_get_path_separator();
strncpy(pidFilePath, _userDataDirectoryPath, MAX_PATH);
strncat(pidFilePath, &separator, 1);
strncat(pidFilePath, SINGLE_INSTANCE_MUTEX_NAME,
MAX_PATH - strnlen(pidFilePath, MAX_PATH) - 1);
safe_strncpy(pidFilePath, _userDataDirectoryPath, sizeof(pidFilePath));
safe_strcat_path(pidFilePath, SINGLE_INSTANCE_MUTEX_NAME, sizeof(pidFilePath));
// We will never close this file manually. The operating system will
// take care of that, because flock keeps the lock as long as the
@@ -576,10 +576,11 @@ bool platform_file_copy(const utf8 *srcPath, const utf8 *dstPath, bool overwrite
if (overwrite) {
dstFile = fopen(dstPath, "wb");
} else {
// Portability note: check your libc's support for "wbx"
dstFile = fopen(dstPath, "wbx");
}
if (dstFile != NULL) {
if (dstFile == NULL) {
if (errno == EEXIST) {
log_warning("platform_file_copy: Not overwriting %s, because overwrite flag == false", dstPath);
return 0;
@@ -591,7 +592,7 @@ bool platform_file_copy(const utf8 *srcPath, const utf8 *dstPath, bool overwrite
// Open both files and check whether they are opened correctly
FILE *srcFile = fopen(srcPath, "rb");
if (!srcFile) {
if (srcFile == NULL) {
fclose(dstFile);
log_error("Could not open source file %s for copying", srcPath);
return 0;

View File

@@ -265,7 +265,7 @@ char *safe_strcat_path(char *destination, const char *source, size_t size)
{
const char pathSeparator = platform_get_path_separator();
size_t length = strlen(destination);
size_t length = strnlen(destination, size);
if (length >= size - 1) {
return destination;
}