GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
mke_mapset.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
8 #include <errno.h>
9 extern int errno;
10 
11 #include <grass/gis.h>
12 
13 int make_mapset(const char *location, const char *mapset)
14 {
15  char buffer[GPATH_MAX];
16  char *buffer2;
17  FILE *fd;
18  struct Cell_head window;
19 
20  /* create the mapset directory */
21  sprintf(buffer, "%s/%s", location, mapset);
22  G_mkdir(buffer);
23 
24  /* give the mapset a default window for the entire location */
25  G_get_default_window(&window);
26  G_put_window(&window);
27 
28  /* generate DB settings file in new mapset */
29  G_asprintf(&buffer2, "%s/%s/VAR", location, mapset);
30  if ((fd = fopen(buffer2, "w")) == NULL) {
31  perror("fopen");
32  G_fatal_error("Cannot create <%s> file in new mapset", buffer2);
33  }
34  fprintf(fd, "DB_DRIVER: dbf\n");
35  fprintf(fd, "DB_DATABASE: $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\n");
36  fclose(fd);
37  G_free(buffer2);
38 
39  /* Make the dbf/ subdirectory */
40  sprintf(buffer, "%s/%s/dbf", location, mapset);
41  if (G_mkdir(buffer) != 0)
42  return -1;
43 
44  return (0);
45 }
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
int G_mkdir(const char *path)
Creates a new directory.
Definition: paths.c:17
FILE * fd
Definition: g3dcolor.c:368
int make_mapset(const char *, const char *)
Definition: mke_mapset.c:13
int G_get_default_window(struct Cell_head *window)
read the default region
Definition: get_window.c:115
int G_asprintf(char **out, const char *fmt,...)
Definition: asprintf.c:116
int G_put_window(const struct Cell_head *window)
write the database region
Definition: put_window.c:32
return NULL
Definition: dbfopen.c:1394
fclose(fd)
int errno
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.