|
@@ -38,24 +38,27 @@ int G_copy_file(const char *infile, const char *outfile)
|
|
|
|
|
|
infp = fopen(infile, "r");
|
|
infp = fopen(infile, "r");
|
|
if (infp == NULL) {
|
|
if (infp == NULL) {
|
|
- G_warning("Cannot open %s for reading: %s", infile, strerror(errno));
|
|
|
|
- return 0;
|
|
|
|
|
|
+ G_warning("Cannot open %s for reading: %s", infile, strerror(errno));
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
outfp = fopen(outfile, "w");
|
|
outfp = fopen(outfile, "w");
|
|
if (outfp == NULL) {
|
|
if (outfp == NULL) {
|
|
- G_warning("Cannot open %s for writing: %s", outfile, strerror(errno));
|
|
|
|
- return 0;
|
|
|
|
|
|
+ G_warning("Cannot open %s for writing: %s", outfile, strerror(errno));
|
|
|
|
+ fclose(infp);
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
while ((inchar = getc(infp)) != EOF) {
|
|
while ((inchar = getc(infp)) != EOF) {
|
|
- /* Read a character at a time from infile until EOF
|
|
|
|
- * and copy to outfile */
|
|
|
|
- outchar = putc(inchar, outfp);
|
|
|
|
- if (outchar != inchar) {
|
|
|
|
- G_warning("Error writing to %s", outfile);
|
|
|
|
- return 0;
|
|
|
|
- }
|
|
|
|
|
|
+ /* Read a character at a time from infile until EOF
|
|
|
|
+ * and copy to outfile */
|
|
|
|
+ outchar = putc(inchar, outfp);
|
|
|
|
+ if (outchar != inchar) {
|
|
|
|
+ G_warning("Error writing to %s", outfile);
|
|
|
|
+ fclose(infp);
|
|
|
|
+ fclose(outfp);
|
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
fflush(outfp);
|
|
fflush(outfp);
|
|
|
|
|