mirror of
https://github.com/kevinbentley/Descent3.git
synced 2025-01-22 11:28:56 +00:00
Remove unused ddio_GetTempFileName()
This commit is contained in:
parent
3e402d78d5
commit
627ab62f1f
@ -374,15 +374,6 @@ void ddio_MakePath(char *newPath, const char *absolutePathHeader, const char *su
|
||||
void ddio_DoForeachFile(const std::filesystem::path &search_path, const std::regex ®ex,
|
||||
const std::function<void(std::filesystem::path)> &func);
|
||||
|
||||
// Generates a temporary filename based on the prefix, and basedir
|
||||
// Parameters:
|
||||
// basedir - directory to put the files
|
||||
// prefix - prefix for the temp filename
|
||||
// filename - buffer to hold generated filename (must be at least _MAX_PATH in length)
|
||||
//
|
||||
// Returns TRUE if successful, FALSE if an error
|
||||
bool ddio_GetTempFileName(const char *basedir, const char *prefix, char *filename);
|
||||
|
||||
/**
|
||||
* Generates a temporary filename based on the prefix in basedir. Function ensures that generated
|
||||
* filename does not exists in basedir directory.
|
||||
|
@ -266,72 +266,6 @@ int ddio_GetFileSysRoots(char **roots, int max_roots) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Generates a temporary filename based on the prefix, and basedir
|
||||
// Parameters:
|
||||
// basedir - directory to put the files
|
||||
// prefix - prefix for the temp filename
|
||||
// filename - buffer to hold generated filename (must be at least _MAX_PATH in length)
|
||||
//
|
||||
// Returns TRUE if successful, FALSE if an error
|
||||
bool ddio_GetTempFileName(const char *basedir, const char *prefix, char *filename) {
|
||||
char old_workdir[_MAX_PATH];
|
||||
bool success = false;
|
||||
|
||||
if (strlen(prefix) > 64)
|
||||
return false;
|
||||
|
||||
ddio_GetWorkingDir(old_workdir, _MAX_PATH);
|
||||
|
||||
if (!ddio_SetWorkingDir(basedir)) {
|
||||
return false; // invalid base directory
|
||||
}
|
||||
|
||||
char randname[10];
|
||||
int index;
|
||||
int tries = 0;
|
||||
char rc;
|
||||
|
||||
bool created = false;
|
||||
|
||||
index = 0;
|
||||
|
||||
while (!success && tries < 20) {
|
||||
// generate a bunch of random characters
|
||||
rc = (rand() % 128);
|
||||
if ((rc >= 'a' && rc <= 'z') || (rc >= 'A' && rc <= 'Z') || (rc >= '0' && rc <= '9')) {
|
||||
// valid character
|
||||
randname[index] = rc;
|
||||
index++;
|
||||
|
||||
if (index == 10) {
|
||||
// we hit the size of our max, see if we generated a unique filename
|
||||
char t[_MAX_PATH];
|
||||
randname[9] = '\0';
|
||||
snprintf(t, sizeof(t), "%s%s.tmp", prefix, randname);
|
||||
|
||||
// see if we can find this file
|
||||
FILE *fd = fopen(t, "rb");
|
||||
if (!fd) {
|
||||
// we found a good file!
|
||||
ddio_MakePath(filename, basedir, t, NULL);
|
||||
success = true;
|
||||
created = true;
|
||||
} else {
|
||||
// already taken
|
||||
fclose(fd);
|
||||
tries++;
|
||||
index = 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
continue; // try again
|
||||
}
|
||||
}
|
||||
|
||||
ddio_SetWorkingDir(old_workdir);
|
||||
return created;
|
||||
}
|
||||
|
||||
bool ddio_CheckProcess(int pid) {
|
||||
if (kill(pid, 0) == -1) {
|
||||
/* some other error, log it */
|
||||
|
@ -271,14 +271,6 @@ void ddio_MakePath(char *newPath, const char *absolutePathHeader, const char *su
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
bool ddio_GetTempFileName(const char *basedir, const char *prefix, char *filename) {
|
||||
|
||||
if (!GetTempFileName(basedir, prefix, 0, filename))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
// retrieve root names, free up roots array (allocated with malloc) after use
|
||||
int ddio_GetFileSysRoots(char **roots, int max_roots) {
|
||||
char buffer[100];
|
||||
|
Loading…
Reference in New Issue
Block a user