Fix wrong sprintf usage: the parameters use the restrict keyword so they may not point to the same location.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5286 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
33a005c801
commit
c26a34d4a5
|
@ -141,7 +141,7 @@ bool CreateDir(const char *path)
|
||||||
return true;
|
return true;
|
||||||
DWORD error = GetLastError();
|
DWORD error = GetLastError();
|
||||||
if (error == ERROR_ALREADY_EXISTS) {
|
if (error == ERROR_ALREADY_EXISTS) {
|
||||||
WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path);
|
WARN_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: already exists", path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path, error);
|
ERROR_LOG(COMMON, "CreateDir: CreateDirectory failed on %s: %i", path, error);
|
||||||
|
@ -153,7 +153,7 @@ bool CreateDir(const char *path)
|
||||||
int err = errno;
|
int err = errno;
|
||||||
|
|
||||||
if (err == EEXIST) {
|
if (err == EEXIST) {
|
||||||
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path);
|
WARN_LOG(COMMON, "CreateDir: mkdir failed on %s: already exists", path);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,7 +297,7 @@ bool Copy(const char *srcFilename, const char *destFilename)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// write output
|
// write output
|
||||||
int wnum = fwrite(buffer, sizeof(char), rnum, output);
|
int wnum = fwrite(buffer, sizeof(char), rnum, output);
|
||||||
if (wnum != rnum)
|
if (wnum != rnum)
|
||||||
|
@ -492,34 +492,39 @@ bool DeleteDirRecursively(const char *directory)
|
||||||
//Create directory and copy contents (does not overwrite existing files)
|
//Create directory and copy contents (does not overwrite existing files)
|
||||||
void CopyDir(const char *source_path, const char *dest_path)
|
void CopyDir(const char *source_path, const char *dest_path)
|
||||||
{
|
{
|
||||||
if (!File::Exists(source_path))
|
if (!strcmp(source_path, dest_path)) return;
|
||||||
return;
|
if (!File::Exists(source_path)) return;
|
||||||
|
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
|
||||||
|
|
||||||
if (!File::Exists(dest_path)) File::CreateFullPath(dest_path);
|
char *virtualName;
|
||||||
char *virtualName;
|
struct dirent dirent, *result = NULL;
|
||||||
struct dirent dirent, *result = NULL;
|
DIR *dirp = opendir(source_path);
|
||||||
DIR *dirp = opendir(source_path);
|
if (!dirp) return;
|
||||||
if (!dirp)
|
|
||||||
return;
|
while (!readdir_r(dirp, &dirent, &result) && result)
|
||||||
while (!readdir_r(dirp, &dirent, &result) && result) {
|
{
|
||||||
virtualName = result->d_name;
|
virtualName = result->d_name;
|
||||||
// check for "." and ".."
|
// check for "." and ".."
|
||||||
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
if (((virtualName[0] == '.') && (virtualName[1] == '\0')) ||
|
||||||
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
((virtualName[0] == '.') && (virtualName[1] == '.') &&
|
||||||
(virtualName[2] == '\0')))
|
(virtualName[2] == '\0')))
|
||||||
continue;
|
continue;
|
||||||
char source[300], dest[300];
|
|
||||||
sprintf(source, "%s%s", source_path, virtualName);
|
char source[FILENAME_MAX], dest[FILENAME_MAX];
|
||||||
sprintf(dest, "%s%s", dest_path, virtualName);
|
sprintf(source, "%s%s", source_path, virtualName);
|
||||||
if (IsDirectory(source)) {
|
sprintf(dest, "%s%s", dest_path, virtualName);
|
||||||
sprintf(source, "%s/", source);
|
if (IsDirectory(source))
|
||||||
sprintf(dest, "%s/", dest);
|
{
|
||||||
if (!File::Exists(dest)) File::CreateFullPath(dest);
|
const unsigned int srclen = strlen(source);
|
||||||
CopyDir(source, dest);
|
const unsigned int destlen = strlen(dest);
|
||||||
} else
|
source[srclen] = '/'; source[srclen+1] = '\0';
|
||||||
if (!File::Exists(dest)) File::Copy(source, dest);
|
dest[destlen] = '/'; dest[destlen+1] = '\0';
|
||||||
}
|
if (!File::Exists(dest)) File::CreateFullPath(dest);
|
||||||
closedir(dirp);
|
CopyDir(source, dest);
|
||||||
|
}
|
||||||
|
else if (!File::Exists(dest)) File::Copy(source, dest);
|
||||||
|
}
|
||||||
|
closedir(dirp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue