Commit d1500bc2 authored by mercury233's avatar mercury233

make `myfilesystem.h` self-contained

parent fcebe3ee
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#ifndef _WIN32 #ifndef _WIN32
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
#include <string>
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
...@@ -182,7 +184,7 @@ public: ...@@ -182,7 +184,7 @@ public:
bool success = true; bool success = true;
TraversalDir(dir, [dir, &success](const char *name, bool isdir) { TraversalDir(dir, [dir, &success](const char *name, bool isdir) {
char full_path[1024]; char full_path[1024];
int len = mysnprintf(full_path, "%s/%s", dir, name); int len = std::snprintf(full_path, sizeof(full_path), "%s/%s", dir, name);
if (len < 0 || len >= (int)(sizeof full_path)) { if (len < 0 || len >= (int)(sizeof full_path)) {
success = false; success = false;
return; return;
...@@ -228,7 +230,7 @@ public: ...@@ -228,7 +230,7 @@ public:
while((dirp = readdir(dir)) != nullptr) { while((dirp = readdir(dir)) != nullptr) {
file_unit funit; file_unit funit;
char fname[1024]; char fname[1024];
int len = mysnprintf(fname, "%s/%s", path, dirp->d_name); int len = std::snprintf(fname, sizeof(fname), "%s/%s", path, dirp->d_name);
if (len < 0 || len >= (int)(sizeof fname)) if (len < 0 || len >= (int)(sizeof fname))
continue; continue;
stat(fname, &fileStat); stat(fname, &fileStat);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment