X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fos.c;h=dacd5802e8b031bc0d31dd86cc27b20fda79ac2b;hp=383473e64585d461ea46cbd09a856574d7e188e0;hb=3d73649bf0e39778e715a07da902d0a858065a43;hpb=53bc7f90f1b258112e8f804a1894e29810c2a4e4 diff --git a/lib/os.c b/lib/os.c index 383473e..dacd580 100755 --- a/lib/os.c +++ b/lib/os.c @@ -210,7 +210,7 @@ char* mktempname(char*ptr) { // 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,lrand48(),lrand48()); + sprintf(ptr, "%s%s%08x%08x",dir,sep,(unsigned int)lrand48(),(unsigned int)lrand48()); #else # ifdef HAVE_RAND sprintf(ptr, "%s%s%08x%08x",dir,sep,rand(),rand()); @@ -269,7 +269,38 @@ void memfile_close(memfile_t*file) #else free(file->data); #endif - file->data = file->len = 0; + file->data = 0; + file->len = 0; free(file); } +void move_file(const char*from, const char*to) +{ + int result = rename(from, to); + + if(result==0) return; //done! + + /* if we can't rename, for some reason, copy the file + manually */ + FILE*fi = fopen(from, "rb"); + if(!fi) { + perror(from); + return; + } + FILE*fo = fopen(to, "wb"); + if(!fo) { + perror(to); + return; + } + char buffer[16384]; + while(1) { + int bytes = fread(buffer, 16384, 1, fi); + if(bytes<=0) + return; + fwrite(buffer, bytes, 1, to); + } + + fclose(fo); + fclose(fi); +} +