X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=blobdiff_plain;f=lib%2Fos.c;h=dacd5802e8b031bc0d31dd86cc27b20fda79ac2b;hp=fddaee904c0f6f79f482c4e9a0a234d1c27a87e3;hb=944d0b42a196bd412c12c6c06fd0e4f301d4a1c7;hpb=879464ce804e0c877db5f4b47fdbfee812f99731 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); +} +