GRASS 8 Programmer's Manual 8.6.0dev(2026)-4bb960b182
Loading...
Searching...
No Matches
overwrite.c
Go to the documentation of this file.
1/*!
2 * \file lib/gis/overwrite.c
3 *
4 * \brief GIS Library - Check for overwrite.
5 *
6 * SPDX-FileCopyrightText: 2001-2008, 2010 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author GRASS Development Team, Martin Landa <landa.martin gmail.com>
10 */
11
12#include <stdlib.h>
13#include <string.h>
14#include <grass/gis.h>
15
16/*!
17 * \brief Check for overwrite mode
18 *
19 * Check variables OVERWRITE, GRASS_OVERWRITE and '--o' flag.
20 *
21 * The parser G_parser() checks if the map already exists in current mapset,
22 * we can switch out the check and do it
23 * in the module after the parser.
24 *
25 * \param argc number of arguments
26 * \param argv array of arguments
27 *
28 * \return 1 if overwrite
29 * \return 0 if not overwrite
30 */
31int G_check_overwrite(int argc, char **argv)
32{
33 const char *overstr;
34 int overwrite;
35
36 overwrite = 0;
37 if ((overstr = G_getenv_nofatal("OVERWRITE"))) {
38 overwrite = atoi(overstr);
39 }
40
41 /* check if inherited GRASS_OVERWRITE is 1 */
42 if (!overwrite && (overstr = getenv("GRASS_OVERWRITE"))) {
43 overwrite = atoi(overstr);
44 }
45
46 /* check for --o or --overwrite option */
47 if (!overwrite) {
48 int i;
49
50 for (i = 0; i < argc; i++) {
51 if (strcmp(argv[i], "--o") == 0 ||
52 strcmp(argv[i], "--overwrite") == 0) {
53 overwrite = 1;
54 break;
55 }
56 }
57 }
58
59 G_setenv_nogisrc("OVERWRITE", "1");
60
61 return overwrite;
62}
const char * G_getenv_nofatal(const char *)
Get environment variable.
Definition env.c:403
void G_setenv_nogisrc(const char *, const char *)
Set environment name to value (doesn't update .gisrc)
Definition env.c:470
int G_check_overwrite(int argc, char **argv)
Check for overwrite mode.
Definition overwrite.c:31