GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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. More...
 
int G_mkstemp (char *template, int flags, int mode)
 Returns a file descriptor. More...
 
FILE * G_mkstemp_fp (char *template, int flags, int mode)
 Returns a file descriptor. More...
 

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.

Referenced by ami_single_temp_name().

◆ 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 162 of file mkstemp.c.

◆ 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 104 of file mkstemp.c.