14 #include <sys/types.h> 21 #include "libwfut/platform.h" 26 #define mkdir(path,mode) _mkdir(path) 32 FILE *os_create_tmpfile() {
35 int ret = GetTempPathA(MAX_PATH, path);
36 if(ret > MAX_PATH || (ret == 0)){
39 char filename[MAX_PATH];
41 ret = GetTempFileNameA(path,
"wfu",0,filename);
43 sprintf(filename,
"%swfut%d.tmp",path,rand());
47 return fopen(filename,
"w+bD");
53 void os_free_tmpfile(FILE *fp) {
59 int os_mkdir(
const std::string &dir) {
60 return mkdir(dir.c_str(), 0700);
63 bool os_exists(
const std::string &file) {
65 if (::stat(file.c_str(), &info) == 0) {
72 int os_set_executable(
const std::string &file) {
78 if (::stat(file.c_str(), &info) == 0) {
80 mode_t mode = info.st_mode;
81 mode |= S_IXGRP | S_IXOTH | S_IXUSR;
85 return chmod(file.c_str(), mode);
91 int os_dir_walk(
const std::string &path,
const std::list<std::string> &excludes, std::list<std::string> &files) {
92 DIR *d = opendir(path.c_str());
94 struct dirent *dent = readdir(d);
96 const std::string d_name(dent->d_name);
97 if (d_name !=
"." && d_name !=
".." && std::find(excludes.begin(), excludes.end(), d_name) == excludes.end()) {
100 stat(d_name.c_str(), &filestat);
101 if (S_ISDIR(filestat.st_mode)) {
102 const std::string &pathname = path +
"/" + d_name;
103 os_dir_walk(pathname, excludes, files);
104 }
else if (S_ISREG(filestat.st_mode)) {
105 const std::string &filename = path +
"/" + d_name;
106 files.push_back(filename);