Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <stdio.h>
00016 #include <errno.h>
00017 #include <string.h>
00018
00019 #include <grass/gis.h>
00020
00034 int G_copy_file(const char *infile, const char *outfile)
00035 {
00036 FILE *infp, *outfp;
00037 int inchar, outchar;
00038
00039 infp = fopen(infile, "r");
00040 if (infp == NULL) {
00041 G_warning("Cannot open %s for reading: %s", infile, strerror(errno));
00042 return 0;
00043 }
00044
00045 outfp = fopen(outfile, "w");
00046 if (outfp == NULL) {
00047 G_warning("Cannot open %s for writing: %s", outfile, strerror(errno));
00048 return 0;
00049 }
00050
00051 while ((inchar = getc(infp)) != EOF) {
00052
00053
00054 outchar = putc(inchar, outfp);
00055 if (outchar != inchar) {
00056 G_warning("Error writing to %s", outfile);
00057 return 0;
00058 }
00059 }
00060 fflush(outfp);
00061
00062 fclose(infp);
00063 fclose(outfp);
00064
00065 return 1;
00066 }