aboutsummaryrefslogtreecommitdiff
path: root/lib/envop.h
blob: 82be3a54a9901f0565c52944c28bb78c991daff9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/* Environment and environment operation definitions for GNU Pies.
   Copyright (C) 2019 Sergey Poznyakoff

   GNU Pies is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GNU Pies is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Pies.  If not, see <http://www.gnu.org/licenses/>. */

/* Environment structure */
struct environ
{
  char **env_base;
  size_t env_count;
  size_t env_max;
};
typedef struct environ environ_t;

environ_t *environ_create (char **);
void environ_free (environ_t *env);
int environ_add (environ_t *env, char const *def);
int environ_set (environ_t *env, char const *name, char const *val);
int environ_unset (environ_t *env, char const *name, char const *val);
int environ_unset_glob (environ_t *env, const char *pattern);
static inline char **
environ_ptr (environ_t *env)
{
  return env->env_base;
}

/* Environment operation codes.
   Elements in a oplist are sorted in that order. */
enum envop_code
  {
    envop_clear,   /* Clear environment */
    envop_keep,    /* Keep variable when clearing */
    envop_set,     /* Set variable */
    envop_unset    /* Unset variable */
  };

struct envop_entry    /* Environment operation entry */
{
  struct envop_entry *next; /* Next entry in the list */
  enum envop_code code;     /* Operation code */
  char *name;               /* Variable name (or globbing pattern) */
  char *value;              /* Value of the variable */
};

typedef struct envop_entry envop_t;

int wildmatch (char const *expr, char const *name, size_t len);

int envop_entry_add (envop_t **head,
		     enum envop_code code,
		     char const *name, char const *value);

int envop_exec (envop_t *op, environ_t *env);
void envop_free (envop_t *op);



Return to:

Send suggestions and report system problems to the System administrator.