mirror of
https://github.com/pdf2htmlEX/pdf2htmlEX.git
synced 2024-12-22 04:50:09 +00:00
clean detection for WIN32
This commit is contained in:
parent
6993ef1368
commit
166efc3892
@ -10,25 +10,15 @@
|
||||
#include <iostream>
|
||||
#include <cstdio>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "TmpFiles.h"
|
||||
#include "Param.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
# define STAT stat
|
||||
# define RMDIR rmdir
|
||||
#else
|
||||
# include <direct.h>
|
||||
# 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;
|
||||
}
|
||||
|
@ -42,12 +42,6 @@ using namespace pdf2htmlEX;
|
||||
Param param;
|
||||
ArgParser argparser;
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <iomanip>
|
||||
# include <libgen.h>
|
||||
# include <direct.h>
|
||||
#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<char> 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();
|
||||
|
@ -12,15 +12,6 @@
|
||||
|
||||
#include "path.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
# include <direct.h>
|
||||
# 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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user