Loading...
Searching...
No Matches
tempfile.c File Reference

GIS Library - Temporary file functions. More...

`#include <string.h>`
`#include <unistd.h>`
`#include <sys/stat.h>`
`#include <stdlib.h>`
`#include <grass/gis.h>`
`#include "gis_local_proto.h"`
Include dependency graph for tempfile.c:

Go to the source code of this file.

## Functions

void | G_init_tempfile (void)
| Initialize environment for creating tempfiles.
char * | G_tempfile (void)
| Returns a temporary file name.
char * | G_tempfile_basedir (const char *basedir)
| Returns a temporary file name.
char * | G_tempfile_pid (int pid)
| Create tempfile from process id.
char * | G_tempfile_pid_basedir (int pid, const char *basedir)
| Create tempfile from process id in given base directory.
void | G_temp_element (char *element)
| Populates element with a path string.
void | G__temp_element (char *element, int tmp)
| Populates element with a path string (internal use only!).
void | G__temp_element_basedir (char *element, const char *basedir)
| Populates element with a path string (internal use only!).

## Detailed Description

GIS Library - Temporary file functions.

(C) 2001-2015 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
  Original author CERL

Definition in file tempfile.c.

## Function Documentation

## G__temp_element()

void G__temp_element | ( | char * | element,
|  | int | tmp )

Populates element with a path string (internal use only!).

Parameters

  [out] | element | element name
  | tmp | TRUE to use G_make_mapset_element_tmp() instead of G_make_mapset_element()

Definition at line 160 of file tempfile.c.

References G__machine_name(), G_debug(), G_make_mapset_object_group(), G_make_mapset_object_group_tmp(), NULL, and strcpy.

Referenced by G_temp_element().

## G__temp_element_basedir()

void G__temp_element_basedir | ( | char * | element,
|  | const char * | basedir )

Populates element with a path string (internal use only!).

Parameters

  [out] | element | element name
  | basedir |

Definition at line 185 of file tempfile.c.

References G__machine_name(), G_debug(), G_make_mapset_object_group(), G_make_mapset_object_group_basedir(), NULL, and strcpy.

Referenced by G_tempfile_pid_basedir().

## G_init_tempfile()

void G_init_tempfile | ( | void |  | ) |

Initialize environment for creating tempfiles.

Definition at line 29 of file tempfile.c.

References G_init_counter(), G_initialize_done(), and G_is_initialized().

Referenced by G_init_all(), G_tempfile_pid(), and G_tempfile_pid_basedir().

## G_temp_element()

void G_temp_element | ( | char * | element | ) |

Populates element with a path string.

Parameters

  [out] | element | element name

Definition at line 148 of file tempfile.c.

References FALSE, and G__temp_element().

Referenced by G_tempfile_pid(), and main().

## G_tempfile()

char * G_tempfile | ( | void |  | ) |

Returns a temporary file name.

This routine returns a pointer to a string containing a unique temporary file name that can be used as a temporary file within the module. Successive calls to G_tempfile() will generate new names. Only the file name is generated. The file itself is not created. To create the file, the module must use standard UNIX functions which create and open files, e.g., creat() or fopen().

Successive calls will generate different names the names are of the form pid.n where pid is the programs process id number and n is a unique identifier.

Note: It is recommended to unlink() (remove) the temp file on exit/error. Only if GRASS is left with 'exit', the GIS mapset management will clean up the temp directory (ETC/clean_temp).

Returns
  pointer to a character string containing the name. The name is copied to allocated memory and may be released by the unix free() routine.

Definition at line 62 of file tempfile.c.

References G_tempfile_pid().

Referenced by G__json(), and PS_Graph_set().

## G_tempfile_basedir()

char * G_tempfile_basedir | ( | const char * | basedir | ) |

Returns a temporary file name.

Similar to G_tempfile(), but the temporary file name will include a provided base directory instead of the path to the current mapset.

Returns
  pointer to a character string containing the name. The name is copied to allocated memory and may be released by the unix free() routine.

Definition at line 77 of file tempfile.c.

References G_tempfile_pid_basedir().

## G_tempfile_pid()

char * G_tempfile_pid | ( | int | pid | ) |

Create tempfile from process id.

See G_tempfile().

Parameters

  pid |

Returns
  pointer to string path

Definition at line 90 of file tempfile.c.

References G_counter_next(), G_debug(), G_file_name(), G_init_tempfile(), G_mapset(), G_store(), G_temp_element(), and name.

Referenced by G_tempfile().

## G_tempfile_pid_basedir()

char * G_tempfile_pid_basedir | ( | int | pid,
|  | const char * | basedir )

Create tempfile from process id in given base directory.

See G_tempfile_basedir().

Parameters

  pid |
  basedir |

Returns
  pointer to string path

Definition at line 121 of file tempfile.c.

References G__temp_element_basedir(), G_counter_next(), G_debug(), G_file_name_basedir(), G_init_tempfile(), G_mapset(), G_store(), and name.

Referenced by G_tempfile_basedir().