diff options
-rw-r--r-- | platform/x11/x11_main.c | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/platform/x11/x11_main.c b/platform/x11/x11_main.c index fe2daa87..edbb9fa8 100644 --- a/platform/x11/x11_main.c +++ b/platform/x11/x11_main.c @@ -317,13 +317,38 @@ void winreplacefile(char *source, char *target) void wincopyfile(char *source, char *target) { - char *buf = malloc(strlen(source)+strlen(target)+5); - if (buf) + FILE *in, *out; + char buf[32 << 10]; + int n; + + in = fopen(source, "rb"); + if (!in) + { + winerror(&gapp, "cannot open source file for copying"); + return; + } + out = fopen(target, "wb"); + if (!out) + { + winerror(&gapp, "cannot open target file for copying"); + fclose(in); + return; + } + + for (;;) { - sprintf(buf, "cp %s %s", source, target); - system(buf); - free(buf); + n = fread(buf, 1, sizeof buf, in); + fwrite(buf, 1, n, out); + if (n < sizeof buf) + { + if (ferror(in)) + winerror(&gapp, "cannot read data from source file"); + break; + } } + + fclose(out); + fclose(in); } void cleanup(pdfapp_t *app) |