]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
file copying now uses a 2KB buffer
authorDipanshu <dipanshu231099@gmail.com>
Thu, 23 Jul 2020 13:09:11 +0000 (18:39 +0530)
committerTill Kamppeter <till.kamppeter@gmail.com>
Thu, 20 Aug 2020 20:08:25 +0000 (22:08 +0200)
(cherry picked from commit 4abffecbf853619ab9403badf2b7eb0bc32e406f)

utils/cups-browsed.c

index 2f8db173cf62a3363bdd786c742b96ea006e5ab6..6871672f126e44b37948dd733bb2db0c2ef51a50 100644 (file)
@@ -711,9 +711,19 @@ long int findLogFileSize()
 }
 
 void copyToFile(FILE **fp1, FILE **fp2){
-  char ch;
-  while((ch = getc(*fp1)) != EOF)
-    putc(ch, *fp2);
+  int buffer_size = 2048;
+  char *buf = (char*) malloc(sizeof(char)*buffer_size);
+  if(!buf){
+    fprintf(stderr,"Error creating buffer for debug logging\n");
+    return;
+  }
+  fseek(*fp1, 0, SEEK_SET);
+  size_t r = fread(buf, sizeof(char), sizeof(buffer_size)-1, *fp1);
+  while(r == sizeof(buffer_size)-1){
+    fwrite(buf, sizeof(char), sizeof(buffer_size)-1, *fp2);
+    r = fread(buf, sizeof(char), sizeof(buffer_size)-1, *fp1);
+  }
+  fwrite(buf, sizeof(char), r, *fp2);
 }
 
 void