GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
tempfile.c
Go to the documentation of this file.
1 
17 #include <string.h>
18 #include <unistd.h>
19 #include <sys/stat.h>
20 #include <grass/gis.h>
21 
22 
47 char *G_tempfile(void)
48 {
49  return G__tempfile(getpid());
50 }
51 
52 
62 char *G__tempfile(int pid)
63 {
64  char path[GPATH_MAX];
65  char name[GNAME_MAX];
66  char element[100];
67  static int uniq = 0;
68  struct stat st;
69 
70  if (pid <= 0)
71  pid = getpid();
72  G__temp_element(element);
73  do {
74  sprintf(name, "%d.%d", pid, uniq++);
75  G__file_name(path, element, name, G_mapset());
76  }
77  while (stat(path, &st) == 0);
78 
79  return G_store(path);
80 }
81 
82 
90 int G__temp_element(char *element)
91 {
92  const char *machine;
93 
94  strcpy(element, ".tmp");
95  machine = G__machine_name();
96  if (machine != NULL && *machine != 0) {
97  strcat(element, "/");
98  strcat(element, machine);
99  }
100  G__make_mapset_element(element);
101 
102  return 0;
103 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int G__temp_element(char *element)
Populates element with a path string.
Definition: tempfile.c:90
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
string name
Definition: render.py:1314
char * G_tempfile(void)
Returns a temporary file name.
Definition: tempfile.c:47
char * G__machine_name(void)
Definition: mach_name.c:23
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
return NULL
Definition: dbfopen.c:1394
int G__make_mapset_element(const char *p_element)
Create element in the current mapset.
Definition: mapset_msc.c:34
char * G__tempfile(int pid)
Create tempfile from process id.
Definition: tempfile.c:62