00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <string.h>
00025 #include <unistd.h>
00026 #include <sys/stat.h>
00027 #include <grass/gis.h>
00028
00049 char *G_tempfile(void)
00050 {
00051 return G__tempfile(getpid());
00052 }
00053
00054 char *G__tempfile (int pid)
00055 {
00056 char path[1024];
00057 char name[GNAME_MAX];
00058 char element[100];
00059 static int uniq = 0;
00060 struct stat st;
00061
00062 if (pid <= 0)
00063 pid = getpid();
00064 G__temp_element(element);
00065 do
00066 {
00067 sprintf (name, "%d.%d", pid, uniq++) ;
00068 G__file_name (path, element, name, G_mapset()) ;
00069 }
00070 while (stat(path, &st) == 0) ;
00071
00072 return G_store (path);
00073 }
00074
00075 int G__temp_element(char *element)
00076 {
00077 char *machine;
00078
00079 strcpy (element, ".tmp");
00080 machine = G__machine_name();
00081 if (machine != NULL && *machine != 0)
00082 {
00083 strcat (element, "/");
00084 strcat (element, machine);
00085 }
00086 G__make_mapset_element (element);
00087
00088 return 0;
00089 }