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

GIS Library - Temporary file functions. More...

`#include <stdio.h>`
`#include <string.h>`
`#include <errno.h>`
`#include <unistd.h>`
`#include <fcntl.h>`
`#include <grass/gis.h>`
`#include <grass/glocale.h>`
Include dependency graph for mkstemp.c:

Go to the source code of this file.

## Macros

#define | MAX_REPLACE 5

## Functions

char * | G_mktemp (char *template)
| Opens a temporary file.
int | G_mkstemp (char *template, int flags, int mode)
| Returns a file descriptor.
FILE * | G_mkstemp_fp (char *template, int flags, int mode)
| Returns a file descriptor.

## Detailed Description

GIS Library - Temporary file functions.

(C) 2014 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
  Glynn Clements

Definition in file mkstemp.c.

## Macro Definition Documentation

## MAX_REPLACE

#define MAX_REPLACE 5

Definition at line 22 of file mkstemp.c.

## Function Documentation

## G_mkstemp()

int G_mkstemp | ( | char * | template,
|  | int | flags,
|  | int | mode )

Returns a file descriptor.

This routine opens the file and returns a descriptor.

The last two take the arguments "flags" and "mode". "flags" should be O_WRONLY or O_RDWR, plus any other desired flags (e.g. O_APPEND). "mode" is the file mode (0666 would be typical).

The functions does not use the PID, although the caller can do so.

In theory, up to 26^5 (= ~12 million) filenames will be attempted until it finds one which doesn't exist.

Returns
  file descriptor

Definition at line 127 of file mkstemp.c.

References G_fatal_error().

Referenced by ami_single_temp_name(), and G_mkstemp_fp().

## G_mkstemp_fp()

FILE * G_mkstemp_fp | ( | char * | template,
|  | int | flags,
|  | int | mode )

Returns a file descriptor.

This routine opens the file and returns a FILE*.

The last two take the arguments "flags" and "mode". "flags" should be O_WRONLY or O_RDWR, plus any other desired flags (e.g. O_APPEND). "mode" is the file mode (0666 would be typical).

The functions does not use the PID, although the caller can do so.

In theory, up to 26^5 (= ~12 million) filenames will be attempted until it finds one which doesn't exist.

Returns
  FILE*

Definition at line 161 of file mkstemp.c.

References G_mkstemp(), and NULL.

## G_mktemp()

char * G_mktemp | ( | char * | template | ) |

Opens a temporary file.

This routine opens the file.

The last two take the arguments "flags" and "mode". "flags" should be O_WRONLY or O_RDWR, plus any other desired flags (e.g. O_APPEND). "mode" is the file mode (0666 would be typical).

The functions does not use the PID, although the caller can do so.

In theory, up to 26^5 (= ~12 million) filenames will be attempted until it finds one which doesn't exist.

Note: G_mktemp() as such it is prone to race conditions (some other process may create that file after G_mktemp() returns).

Returns
  file name

Definition at line 105 of file mkstemp.c.

References NULL.