GRASS Programmer's Manual  6.4.4(2014)-r
key_value3.c
Go to the documentation of this file.
1 
16 #include <grass/gis.h>
17 
29 int G_write_key_value_file(const char *file,
30  const struct Key_Value *kv, int *stat)
31 {
32  FILE *fd;
33 
34  *stat = 0;
35  fd = fopen(file, "w");
36  if (fd == NULL)
37  *stat = -3;
38  else if (G_fwrite_key_value(fd, kv) != 0 || fclose(fd) == EOF)
39  *stat = -4;
40  return (*stat != 0);
41 }
42 
54 struct Key_Value *G_read_key_value_file(const char *file, int *stat)
55 {
56  FILE *fd;
57  struct Key_Value *kv;
58 
59  *stat = 0;
60  fd = fopen(file, "r");
61  if (fd == NULL) {
62  *stat = -1;
63  return NULL;
64  }
65  kv = G_fread_key_value(fd);
66  fclose(fd);
67  if (kv == NULL)
68  *stat = -2;
69  return kv;
70 }
#define NULL
Definition: strings.c:26
struct Key_Value * G_fread_key_value(FILE *fd)
Read key/values pairs from file.
Definition: key_value2.c:51
int G_fwrite_key_value(FILE *fd, const struct Key_Value *kv)
Write key/value pairs to file.
Definition: key_value2.c:27
struct Key_Value * G_read_key_value_file(const char *file, int *stat)
Read key/values pairs from file.
Definition: key_value3.c:54
int G_write_key_value_file(const char *file, const struct Key_Value *kv, int *stat)
Write key/value pairs to file.
Definition: key_value3.c:29
#define file