Skip to content

Commit

Permalink
fs: Remove platform-specific 'fs_copyFile'
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelheilmann committed Jan 18, 2018
1 parent 134b149 commit 1e342fe
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 55 deletions.
29 changes: 0 additions & 29 deletions egolib/src/egolib/Platform/file_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,35 +119,6 @@ int sys_fs_init(const char *root_dir)
return 0;
}

bool fs_copyFile(const std::string& source, const std::string& target)
{
char buf[4096] = EMPTY_CSTR;
int bytes_read;

// Open source file descriptor.
FILE *sourcefd = fopen(source.c_str(), "rb");
if (!sourcefd)
{
return false;
}
// Open target file descriptor.
FILE *targetfd = fopen(target.c_str(), "wb");
if (!targetfd)
{
fclose(sourcefd);
return false;
}
// Read Bytes from the target source file and write them into the target file.
while ((bytes_read = fread(buf, 1, sizeof(buf), sourcefd)))
{
fwrite(buf, 1, bytes_read, targetfd);
}
// Finish file descriptors.
fclose(sourcefd);
fclose(targetfd);
return true;
}

const char *fs_findFirstFile(const char *directory, const char *extension, fs_find_context_t *fs_search)
{
char pattern[PATH_MAX] = EMPTY_CSTR;
Expand Down
17 changes: 0 additions & 17 deletions egolib/src/egolib/Platform/file_mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,6 @@ int sys_fs_init(const char *root_path)
return [dataPath UTF8String];
}

bool fs_copyFile(const std::string& source, const std::string& target)
{
@autoreleasepool {
BOOL didCopy;
NSString *sourcePath, *targetPath;

sourcePath = [[NSString alloc] initWithUTF8String:source.c_str()];
targetPath = [[NSString alloc] initWithUTF8String:target.c_str()];

didCopy = [[NSFileManager defaultManager] copyItemAtPath:sourcePath toPath:targetPath error:nil];

[sourcePath release];
[targetPath release];
return didCopy;
}
}

//---------------------------------------------------------------------------------------------
//Directory Functions--------------------------------------------------------------------------
//---------------------------------------------------------------------------------------------
Expand Down
9 changes: 0 additions & 9 deletions egolib/src/egolib/Platform/file_win.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,6 @@ std::string fs_getConfigDirectory()
return _configPath;
}

bool fs_copyFile(const std::string& source, const std::string& target)
{
if (source.empty() || target.empty())
{
return false;
}
return (TRUE == CopyFile(source.c_str(), target.c_str(), false));
}

//--------------------------------------------------------------------------------------------
// Directory Functions
//--------------------------------------------------------------------------------------------
Expand Down
6 changes: 6 additions & 0 deletions egolib/src/egolib/file_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ int fs_fileIsDirectory(const std::string& pathname)
return id::file_system::is_directory(pathname) ? 1 : 0;
}

//--------------------------------------------------------------------------------------------
bool fs_copyFile(const std::string& source, const std::string& target)
{
return id::file_system::copy_regular_file(source, target, false);
}

//--------------------------------------------------------------------------------------------
int fs_fileExists(const std::string& filename)
{
Expand Down

0 comments on commit 1e342fe

Please sign in to comment.