GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
other.c
Go to the documentation of this file.
1 #include <fcntl.h>
2 #include <sys/stat.h>
3 #include <sys/types.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <grass/gis.h>
7 #include "local_proto.h"
8 
9 static char *filename(const char *name, const char *mapset)
10 {
11  static char path[GPATH_MAX];
12 
13  G__file_name(path, "", name, mapset);
14  return path;
15 }
16 
17 int mapset_permissions(const char *mapset)
18 {
19  int stat;
20 
21  stat = G__mapset_permissions(mapset);
22  if (stat == 1) {
23  if (access(filename(".lock", mapset), 0) == 0)
24  stat = 0;
25  }
26  return stat;
27 }
28 
29 int mapset_message(const char *mapset)
30 {
31  if (printfile(filename(".message", mapset)))
32  hit_return();
33 
34  return 0;
35 }
36 
37 int mapset_question(const char *mapset)
38 {
39  if (printfile(filename(".question", mapset)))
40  return G_yes("Select this mapset? ", -1);
41  return 1;
42 }
43 
44 int printfile(const char *name)
45 {
46  int fd;
47  int n;
48  char buf[1024];
49 
50  fd = open(name, 0);
51  if (fd < 0)
52  return 0;
53  while ((n = read(fd, buf, sizeof buf)) > 0)
54  write(STDOUT_FILENO, buf, n);
55  close(fd);
56  return 1;
57 }
int G__mapset_permissions(const char *mapset)
Check for user mapset permission.
Definition: mapset_msc.c:115
int mapset_message(const char *)
Definition: other.c:29
int mapset_question(const char *)
Definition: other.c:37
FILE * fd
Definition: g3dcolor.c:368
string name
Definition: render.py:1314
int G_yes(const char *question, int dflt)
Ask a yes/no question.
Definition: yes.c:39
int hit_return(void)
Definition: set_data.c:340
int stat
Definition: g3dcolor.c:369
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
Definition: file_name.c:33
int mapset_permissions(const char *)
Definition: other.c:17
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
int printfile(const char *)
Definition: other.c:44
int n
Definition: dataquad.c:291