GRASS Programmer's Manual 6.4.1(2011)
tempfile.c
Go to the documentation of this file.
00001 
00017 #include <string.h>
00018 #include <unistd.h>
00019 #include <sys/stat.h>
00020 #include <grass/gis.h>
00021 
00022 
00047 char *G_tempfile(void)
00048 {
00049     return G__tempfile(getpid());
00050 }
00051 
00052 
00062 char *G__tempfile(int pid)
00063 {
00064     char path[GPATH_MAX];
00065     char name[GNAME_MAX];
00066     char element[100];
00067     static int uniq = 0;
00068     struct stat st;
00069 
00070     if (pid <= 0)
00071         pid = getpid();
00072     G__temp_element(element);
00073     do {
00074         sprintf(name, "%d.%d", pid, uniq++);
00075         G__file_name(path, element, name, G_mapset());
00076     }
00077     while (stat(path, &st) == 0);
00078 
00079     return G_store(path);
00080 }
00081 
00082 
00090 int G__temp_element(char *element)
00091 {
00092     const char *machine;
00093 
00094     strcpy(element, ".tmp");
00095     machine = G__machine_name();
00096     if (machine != NULL && *machine != 0) {
00097         strcat(element, "/");
00098         strcat(element, machine);
00099     }
00100     G__make_mapset_element(element);
00101 
00102     return 0;
00103 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines