X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=tool%2Fpacker.cpp;h=56dfa0334fb3a93fecad03f77a6a763cb3fb39c1;hb=9f7ed91d05f6fc92c2142655b5c815c871d11744;hp=3576472e57b07baa7f2755e9c8012f5b60d0110e;hpb=7abc9c3ed271ed787d57c2f074c9a696fb7b2572;p=libs%2Fdatafile.git diff --git a/tool/packer.cpp b/tool/packer.cpp index 3576472..56dfa03 100644 --- a/tool/packer.cpp +++ b/tool/packer.cpp @@ -19,17 +19,20 @@ Packer::Packer(DataTool &t): IO::File *Packer::tempfile() { + FS::Path tmpdir; + const char *tmp_env = getenv("TMPDIR"); + if(tmp_env) + tmpdir = tmp_env; + else + tmpdir = "/tmp"; + for(unsigned i=0;; ++i) { try { - std::string filename = format("/tmp/mspdatatool.%d", i); - /*filename.reserve(25); - filename.append("/tmp/mspdatatool."); - for(unsigned i=0; i<8; ++i) - filename.append(rand());*/ - IO::File *file = new IO::File(filename, IO::M_RDWR, IO::File::C_NEW); - FS::unlink(filename); + FS::Path filename = tmpdir/format("mspdatatool.%d", i); + IO::File *file = new IO::File(filename.str(), IO::M_RDWR, IO::File::C_NEW); + FS::unlink(filename.str()); return file; } catch(const IO::file_already_exists &) @@ -167,12 +170,14 @@ void Packer::create_pack(const string &fn) IO::File out(fn, IO::M_WRITE); out.write(&dir_buffer[0], base_offset); tmp_file->seek(0, IO::S_BEG); + unsigned bufsize = 1048576; + char *buf = new char[bufsize]; while(!tmp_file->eof()) { - char buf[16384]; - unsigned len = tmp_file->read(buf, sizeof(buf)); + unsigned len = tmp_file->read(buf, bufsize); if(!len) break; out.write(buf, len); } + delete[] buf; }