From 166efc3892418acd0fe79b6d9edfff5d6be9eaf0 Mon Sep 17 00:00:00 2001 From: Lu Wang Date: Mon, 13 Jan 2014 20:37:00 +0800 Subject: [PATCH] clean detection for WIN32 --- src/TmpFiles.cc | 18 ++++-------------- src/pdf2htmlEX.cc | 35 +---------------------------------- src/util/path.cc | 15 +++------------ 3 files changed, 8 insertions(+), 60 deletions(-) diff --git a/src/TmpFiles.cc b/src/TmpFiles.cc index 78d40d9..2ff4956 100644 --- a/src/TmpFiles.cc +++ b/src/TmpFiles.cc @@ -10,25 +10,15 @@ #include #include #include +#include #include "TmpFiles.h" #include "Param.h" using namespace std; -#ifndef _WIN32 -# include -# define STAT stat -# define RMDIR rmdir -#else -# include -# define STAT _stat -# define RMDIR _rmdir -#endif - namespace pdf2htmlEX { - TmpFiles::TmpFiles( const Param& param ) : param( param ) { } @@ -51,9 +41,9 @@ void TmpFiles::add( const string & fn) double TmpFiles::get_total_size() const { double total_size = 0; - struct STAT st; + struct stat st; for(auto iter = tmp_files.begin(); iter != tmp_files.end(); ++iter) { - STAT(iter->c_str(), &st); + stat(iter->c_str(), &st); total_size += st.st_size; } @@ -74,7 +64,7 @@ void TmpFiles::clean() cerr << "Remove temporary file: " << fn << endl; } - RMDIR(param.tmp_dir.c_str()); + rmdir(param.tmp_dir.c_str()); if(param.debug) cerr << "Remove temporary directory: " << param.tmp_dir << endl; } diff --git a/src/pdf2htmlEX.cc b/src/pdf2htmlEX.cc index 2556588..33562dd 100644 --- a/src/pdf2htmlEX.cc +++ b/src/pdf2htmlEX.cc @@ -42,12 +42,6 @@ using namespace pdf2htmlEX; Param param; ArgParser argparser; -#ifdef _WIN32 -# include -# include -# include -#endif - void deprecated_font_suffix(const char * dummy = nullptr) { cerr << "--font-suffix is deprecated. Use `--font-format` instead." << endl; @@ -115,7 +109,7 @@ void embed_parser (const char * str) void prepare_directories() { std::string tmp_dir = param.tmp_dir + "/pdf2htmlEX-XXXXXX"; -#ifndef _WIN32 + errno = 0; unique_ptr pBuf(new char[tmp_dir.size() + 1]); @@ -132,19 +126,6 @@ void prepare_directories() exit(EXIT_FAILURE); } param.tmp_dir = pBuf.get(); -#else - srand((unsigned)time(0)); - int rand_value = (int)((rand() / ((double)RAND_MAX+1.0)) * 1e6); - stringstream ss; - ss << setw(6) << rand_value; - - tmp_dir.erase(tmp_dir.size() - 6); - param.tmp_dir = tmp_dir + ss.str(); - if (mkdir(param.tmp_dir.c_str())) { - cerr << "Cannot create temp directory (" << param.tmp_dir << "): " << strerror(errno) << endl; - exit(EXIT_FAILURE); - } -#endif } void parse_options (int argc, char **argv) @@ -361,22 +342,8 @@ void check_param() int main(int argc, char **argv) { // We need to adjust these directories before parsing the options. -#ifndef _WIN32 param.tmp_dir = "/tmp"; param.data_dir = PDF2HTMLEX_DATA_PATH; -#else - { - // Under Windows, the default data_dir is under /data in the pdf2htmlEX directory - stringstream ss; - ss << dirname(argv[0]) << "/data"; - param.data_dir = ss.str(); - - // Under Windows, the temp path is not under /tmp, find it. - char temppath[MAX_PATH]; - ::GetTempPath(MAX_PATH, temppath); - param.tmp_dir = temppath; - } -#endif parse_options(argc, argv); check_param(); diff --git a/src/util/path.cc b/src/util/path.cc index 0f51399..e0b1b94 100644 --- a/src/util/path.cc +++ b/src/util/path.cc @@ -12,15 +12,6 @@ #include "path.h" -#ifdef _WIN32 -# include -# define STAT _stat -# define MKDIR(A, B) _mkdir(A) -#else -# define STAT stat -# define MKDIR(A, B) mkdir(A, B) -#endif - using std::string; namespace pdf2htmlEX { @@ -35,13 +26,13 @@ void create_directories(const string & path) create_directories(path.substr(0, idx)); } - int r = MKDIR(path.c_str(), S_IRWXU); + int r = mkdir(path.c_str(), S_IRWXU); if(r != 0) { if(errno == EEXIST) { - struct STAT stat_buf; - if((STAT(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) + struct stat stat_buf; + if((stat(path.c_str(), &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) return; }