COOPY » Guide
version 0.6.5
|
00001 #include <coopy/OS.h> 00002 00003 #include <stdio.h> 00004 #include <stdlib.h> 00005 #include <unistd.h> 00006 00007 extern "C" { 00008 #include "tmpdir.h" 00009 #include "tempname.h" 00010 } 00011 00012 #include <coopy/Dbg.h> 00013 00014 using namespace coopy::os; 00015 00016 std::string OS::getTemporaryFilename() { 00017 char buf[10000]; 00018 int r = path_search(buf,sizeof(buf),NULL,"_cpy_",true); 00019 if (r==0) { 00020 r = gen_tempname(buf,0,0,GT_FILE); 00021 //r = mkstemp(buf); 00022 if (r!=-1) close(r); 00023 dbg_printf("Created %s\n", buf); 00024 return buf; 00025 } 00026 return ""; 00027 } 00028 00029 00030 bool OS::deleteFile(const std::string& name) { 00031 int result = unlink(name.c_str()); 00032 if (result!=0) { 00033 fprintf(stderr,"Problem deleting %s\n", name.c_str()); 00034 } else { 00035 dbg_printf("Deleted %s\n", name.c_str()); 00036 } 00037 return result==0; 00038 }