X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fos.c;h=dacd5802e8b031bc0d31dd86cc27b20fda79ac2b;hb=c3cacee02d5a26355bccc9865dc213e47eeb5370;hp=fddaee904c0f6f79f482c4e9a0a234d1c27a87e3;hpb=2391d7ae5d8a145a250a8b80ab8c93ba74eba030;p=swftools.git diff --git a/lib/os.c b/lib/os.c index fddaee9..dacd580 100755 --- a/lib/os.c +++ b/lib/os.c @@ -274,3 +274,33 @@ void memfile_close(memfile_t*file) 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); +} +