1
0
Fork 0
spectre/source/System/File.cpp
Henrik Hautakoski e10daeaaa6
Move everything from global namespace to "sp" namespace
When writing the X11 (linux) implementation there was a problem with X11 defining a "Display" type and we also have a Display class in the engine.

So to fix that problem and minimize the risk for running into other name conflicts. We move everything from global namespace.
2019-09-30 19:10:17 +02:00

40 lines
816 B
C++

#include <string.h>
#include <stdio.h>
#include <Spectre/System/File.h>
namespace sp { namespace file
{
std::string getBasename(const std::string& path) {
size_t p = path.find_last_of('/');
if (p == std::string::npos)
return path;
return path.substr(p + 1);
}
std::string getExtension(const std::string& path) {
std::string base_name = getBasename(path);
size_t p = base_name.find_first_of('.');
if (p == std::string::npos)
return "";
return base_name.substr(p + 1);
}
std::vector<unsigned char> read(const std::string& path) {
std::vector<unsigned char> buf;
FILE *fd = fopen(path.c_str(), "rb");
if (fd) {
fseek(fd, 0, SEEK_END);
buf.resize(ftell(fd));
rewind(fd);
fread(&buf[0], 1, buf.size(), fd);
fclose(fd);
}
return buf;
}
} } // namespace sp::file