Merge remote-tracking branch 'origin/release-v4.5.2'
[WRF.git] / var / da / da_main / copyfile.c
blobeaf1c5388b92316ccc78970d30c6cacae62fa396
1 #include <stdio.h>
2 #include <stdlib.h>
4 int32_t copyfile ( char *ifile, char *ofile)
6 char buff[BUFSIZ];
7 size_t n;
8 FILE *source, *target;
10 source = fopen(ifile, "r");
12 if( source == NULL )
13 { return -1; }
15 target = fopen(ofile, "wb+");
17 if( target == NULL ) {
18 fclose(source);
19 return -1;
22 while( (n=fread(buff,1,BUFSIZ, source)) != 0) {
23 fwrite(buff,1,n,target);
26 fclose(source);
27 fclose(target);
28 return 0;