summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2017-12-01 16:25:39 +0100
committerTor Andersson <tor.andersson@artifex.com>2017-12-13 15:01:05 +0100
commit5722ebc5823381ee57c525cbc0d4dc627009979d (patch)
treef94c74e650c7466e92732b813ee5c76e762d0a05
parent2d6e0ebc7ddf305301e4961b7bc068976100e42f (diff)
downloadmupdf-5722ebc5823381ee57c525cbc0d4dc627009979d.tar.xz
Fix 698787: avoid using "system()" to copy files.
-rw-r--r--platform/x11/x11_main.c35
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)