Browse code

added cli_filecopy()

git-svn-id: file:///var/lib/svn/clamav-devel/trunk/clamav-devel@1206 77e5149b-7576-45b1-b177-96237e5ba77b

Tomasz Kojm authored on 2004/12/20 11:04:58
Showing 3 changed files
... ...
@@ -1,3 +1,7 @@
1
+Mon Dec 20 02:57:29 CET 2004 (tk)
2
+---------------------------------
3
+  * libclamav/others.c: added cli_filecopy()
4
+
1 5
 Mon Dec 20 02:32:30 CET 2004 (tk)
2 6
 ---------------------------------
3 7
   * improved OS/2 support (thanks to Yuri Dario <mc6530*mclink.it>)
... ...
@@ -66,6 +66,10 @@ pthread_mutex_t cli_gentemp_mutex = PTHREAD_MUTEX_INITIALIZER;
66 66
 # endif
67 67
 #endif
68 68
 
69
+#ifndef	O_BINARY
70
+#define	O_BINARY	0
71
+#endif
72
+
69 73
 #define CL_FLEVEL 3 /* don't touch it */
70 74
 
71 75
 #define MAX_ALLOCATION 134217728
... ...
@@ -574,3 +578,29 @@ int cli_memstr(const char *haystack, int hs, const char *needle, int ns)
574 574
 
575 575
     return 0;
576 576
 }
577
+
578
+int cli_filecopy(const char *src, const char *dest)
579
+{
580
+	char *buffer;
581
+	int s, d, bytes;
582
+
583
+
584
+    if((s = open(src, O_RDONLY)) == -1)
585
+	return -1;
586
+
587
+    if((d = open(dest, O_CREAT|O_WRONLY|O_TRUNC|O_BINARY)) == -1) {
588
+	close(s);
589
+	return -1;
590
+    }
591
+
592
+    if(!(buffer = cli_malloc(FILEBUFF)))
593
+	return -1;
594
+
595
+    while((bytes = cli_readn(s, buffer, FILEBUFF)) > 0)
596
+	cli_writen(d, buffer, bytes);
597
+
598
+    free(buffer);
599
+    close(s);
600
+
601
+    return close(d);
602
+}
... ...
@@ -38,5 +38,6 @@ int32_t cli_readint32(const char *buff);
38 38
 char *cli_gentemp(const char *dir);
39 39
 unsigned int cli_rndnum(unsigned int max);
40 40
 int cli_memstr(const char *haystack, int hs, const char *needle, int ns);
41
+int cli_filecopy(const char *src, const char *dest);
41 42
 
42 43
 #endif