From: Matthias Kramm Date: Tue, 23 Mar 2010 00:54:43 +0000 (-0700) Subject: added extension to temp files X-Git-Tag: version-0-9-1~71 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=8589e0d1f5e47c05458033e750fd6182ca704fbe;hp=df102d603f84e64cfd36aef0fddcf70fafac7ee2 added extension to temp files --- diff --git a/lib/devices/pdf.c b/lib/devices/pdf.c index 1e0d6a8..16bb6cf 100644 --- a/lib/devices/pdf.c +++ b/lib/devices/pdf.c @@ -100,7 +100,7 @@ void pdf_startpage(gfxdevice_t*dev, int width, int height) internal_t*i = (internal_t*)dev->internal; if(!i->tempfile) { - i->tempfile = strdup(mktempname(0)); + i->tempfile = strdup(mktempname(0, "pdf")); PDF_begin_document(i->p, i->tempfile, 0, ""); //PDF_set_value(i->p, "compress", 0); @@ -281,14 +281,14 @@ void pdf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t } char tempfile[128]; - mktempname(tempfile); + mktempname(tempfile, "jpg"); gfximage_save_jpeg(img, tempfile, 96); int imgid=-1; if(has_alpha) { char tempfile2[128]; - mktempname(tempfile2); + mktempname(tempfile2, "jpg"); int t; int size = img->width*img->height; unsigned char*alpha = malloc(size); diff --git a/lib/devices/record.c b/lib/devices/record.c index 5f3709a..abace9b 100644 --- a/lib/devices/record.c +++ b/lib/devices/record.c @@ -733,7 +733,7 @@ void gfxdevice_record_init(gfxdevice_t*dev, char use_tempfile) writer_init_growingmemwriter(&i->w, 1048576); } else { char buffer[128]; - i->filename = strdup(mktempname(buffer)); + i->filename = strdup(mktempname(buffer, "gfx")); writer_init_filewriter2(&i->w, i->filename); } i->fontlist = gfxfontlist_create(); diff --git a/lib/os.c b/lib/os.c index dacd580..a4142ff 100755 --- a/lib/os.c +++ b/lib/os.c @@ -192,8 +192,8 @@ static char* getTempDir() return dir; } -char* mktempname(char*ptr) { - static char tmpbuf[128]; +char* mktempname(char*ptr, const char*ext) { + static char tmpbuf[160]; char*dir = getTempDir(); int l = strlen(dir); char*sep = ""; @@ -207,20 +207,24 @@ char* mktempname(char*ptr) { #endif } - // used to be mktemp. This does remove the warnings, but - // It's not exactly an improvement. #ifdef HAVE_LRAND48 - sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48()); + unsigned int r1 = (unsigned int)lrand48(); + unsigned int r2 = (unsigned int)lrand48(); +#elif HAVE_RAND + unsigned int r1 = rand(); + unsigned int r2 = rand(); #else -# ifdef HAVE_RAND - sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand()); -# else - static int count = 1; - sprintf(ptr, "%s%s%08x%04x%04x",dir,sep,time(0),(unsigned int)tmpbuf^((unsigned int)tmpbuf)>>16,count); - count ++; -# endif + static int count = 1; + unsigned int r1 = time(0); + unsigned int r2 = (unsigned int)tmpbuf<<8^count; + count ++; #endif - return ptr; + if(ext) { + sprintf(ptr, "%s%s%04x%04x.%s",dir,sep,r1,r2,ext); + } else { + sprintf(ptr, "%s%s%04x%04x",dir,sep,r1,r2); + } + return ptr; } memfile_t* memfile_open(const char*path) @@ -297,7 +301,7 @@ void move_file(const char*from, const char*to) int bytes = fread(buffer, 16384, 1, fi); if(bytes<=0) return; - fwrite(buffer, bytes, 1, to); + fwrite(buffer, bytes, 1, fo); } fclose(fo); diff --git a/lib/os.h b/lib/os.h index 532aea8..42d4884 100755 --- a/lib/os.h +++ b/lib/os.h @@ -47,7 +47,7 @@ char* getInstallationPath(); char* concatPaths(const char*base, const char*add); char* stripFilename(const char*filename, const char*newext); -char* mktempname(char*buffer); +char* mktempname(char*buffer, const char*ext); void move_file(const char*from, const char*to);