Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libcs/csvar.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 1990-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* Glenn Fowler
23
* AT&T Research
24
*
25
* run time cs var support
26
*/
27
28
#include "cslib.h"
29
30
#ifndef TRUST
31
#define TRUST "/usr/local:/usr" /* trusted root dirs */
32
#endif
33
34
typedef struct
35
{
36
const char* name;
37
const char* trust;
38
const char* value;
39
} Var_t;
40
41
static Var_t var[] =
42
{
43
44
{ /* CS_VAR_LOCAL */ "CS_MOUNT_LOCAL", "/tmp/cs" },
45
{ /* CS_VAR_PROXY */ "CS_MOUNT_PROXY", "/dev/tcp/proxy/inet.proxy" },
46
{ /* CS_VAR_SHARE */ "CS_MOUNT_SHARE", "share/lib/cs" },
47
{ /* CS_VAR_TRUST */ "CS_MOUNT_TRUST", TRUST },
48
49
};
50
51
char*
52
csvar(Cs_t* state, int index, int trust)
53
{
54
register char* s;
55
register Var_t* p;
56
57
if (index < 0 || index >= elementsof(var))
58
return 0;
59
p = &var[index];
60
if (!p->name || trust)
61
return (char*)p->trust;
62
if (!p->value)
63
p->value = ((s = getenv(p->name)) && *s) ? (const char*)s : p->trust;
64
return (char*)p->value;
65
}
66
67
char*
68
_cs_var(int index, int trust)
69
{
70
return csvar(&cs, index, trust);
71
}
72
73