GRASS GIS 7 Programmer's Manual  7.0.3(2016)-r00000
key_value3.c
Go to the documentation of this file.
1 
14 #include <errno.h>
15 #include <string.h>
16 #include <grass/gis.h>
17 #include <grass/glocale.h>
18 
28 void G_write_key_value_file(const char *file,
29  const struct Key_Value *kv)
30 {
31  FILE *fp = fopen(file, "w");
32  if (!fp)
33  G_fatal_error(_("Unable to open output file <%s>: %s"), file, strerror(errno));
34 
35  if (G_fwrite_key_value(fp, kv) != 0)
36  G_fatal_error(_("Error writing file <%s>: %s"), file, strerror(errno));
37 
38  if (fclose(fp) != 0)
39  G_fatal_error(_("Error closing output file <%s>: %s"), file, strerror(errno));
40 }
41 
53 struct Key_Value *G_read_key_value_file(const char *file)
54 {
55  FILE *fp;
56  struct Key_Value *kv;
57 
58  fp = fopen(file, "r");
59  if (!fp)
60  G_fatal_error(_("Unable to open input file <%s>: %s"), file, strerror(errno));
61 
62  kv = G_fread_key_value(fp);
63  if (!kv)
64  G_fatal_error(_("Error reading file <%s>: %s"), file, strerror(errno));
65 
66  if (fclose(fp) != 0)
67  G_fatal_error(_("Error closing input file <%s>: %s"), file, strerror(errno));
68 
69  return kv;
70 }
struct Key_Value * G_fread_key_value(FILE *fd)
Read key/values pairs from file.
Definition: key_value2.c:49
int G_fwrite_key_value(FILE *fd, const struct Key_Value *kv)
Write key/value pairs to file.
Definition: key_value2.c:25
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:159
void G_write_key_value_file(const char *file, const struct Key_Value *kv)
Write key/value pairs to file.
Definition: key_value3.c:28
struct Key_Value * G_read_key_value_file(const char *file)
Read key/values pairs from file.
Definition: key_value3.c:53
#define file