Skip to content

Commit

Permalink
Removed duplicated (and bugged) file_open in FileStream.
Browse files Browse the repository at this point in the history
Use the one in Utils.cpp
  • Loading branch information
jackburton79 committed Jan 9, 2024
1 parent e21b523 commit d8cbc5c
Showing 1 changed file with 1 addition and 42 deletions.
43 changes: 1 addition & 42 deletions streams/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,7 @@
#include <cstring>
#include <dirent.h>


static
FILE*
fopen_case(const char* filename, const char* flags)
{
assert(filename != NULL);
assert(::strlen(filename) > 1);

char* normalizedFileName = ::realpath(filename, NULL);
std::string newPath("/");
char* start = normalizedFileName + 1;
char* end = start + ::strlen(normalizedFileName);
size_t where = 0;
while ((where = ::strcspn(start, "/")) > 0) {
std::string leaf;
leaf.append(start, where);
DIR* dir = ::opendir(newPath.c_str());
if (dir != NULL) {
dirent *entry = NULL;
while ((entry = ::readdir(dir)) != NULL) {
if (!::strcasecmp(entry->d_name, leaf.c_str())) {
if (newPath != "/")
newPath.append("/");
newPath.append(entry->d_name);
break;
}
}
::closedir(dir);
}
start += where + 1;
if (start >= end)
break;
}

FILE* handle = NULL;
if (!::strcasecmp(normalizedFileName, newPath.c_str()))
handle = ::fopen(newPath.c_str(), flags);

::free(normalizedFileName);

return handle;
}
#include "Utils.h"


FileStream::FileStream(const char *filename, int mode)
Expand Down

0 comments on commit d8cbc5c

Please sign in to comment.