GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
copy_file.c
Go to the documentation of this file.
1 
2 /****************************************************************************
3  *
4  * MODULE: GRASS GIS library - copy_file.c
5  * AUTHOR(S): Paul Kelly
6  * PURPOSE: Function to copy one file to another.
7  * COPYRIGHT: (C) 2007 by the GRASS Development Team
8  *
9  * This program is free software under the GNU General Public
10  * License (>=v2). Read the file COPYING that comes with GRASS
11  * for details.
12  *
13  *****************************************************************************/
14 
15 #include <stdio.h>
16 #include <errno.h>
17 #include <string.h>
18 
19 #include <grass/gis.h>
20 
34 int G_copy_file(const char *infile, const char *outfile)
35 {
36  FILE *infp, *outfp;
37  int inchar, outchar;
38 
39  infp = fopen(infile, "r");
40  if (infp == NULL) {
41  G_warning("Cannot open %s for reading: %s", infile, strerror(errno));
42  return 0;
43  }
44 
45  outfp = fopen(outfile, "w");
46  if (outfp == NULL) {
47  G_warning("Cannot open %s for writing: %s", outfile, strerror(errno));
48  return 0;
49  }
50 
51  while ((inchar = getc(infp)) != EOF) {
52  /* Read a character at a time from infile until EOF
53  * and copy to outfile */
54  outchar = putc(inchar, outfp);
55  if (outchar != inchar) {
56  G_warning("Error writing to %s", outfile);
57  return 0;
58  }
59  }
60  fflush(outfp);
61 
62  fclose(infp);
63  fclose(outfp);
64 
65  return 1;
66 }
int G_copy_file(const char *infile, const char *outfile)
Copies one file to another.
Definition: copy_file.c:34
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
fclose(fd)
int errno
FILE * outfp