update gcc 5 patch for 20150222 snapshot
[AROS.git] / rom / dos / findvar.c
blobfe8d56ad799903c85d1e75415b8a3dd2e7af9284
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Find a local variable.
6 Lang: English
7 */
9 #include <aros/debug.h>
10 #include "dos_intern.h"
11 #include <proto/exec.h>
12 #include <proto/utility.h>
13 #include <string.h>
15 /*****************************************************************************
17 NAME */
19 #include <proto/dos.h>
20 #include <dos/var.h>
22 AROS_LH2(struct LocalVar *, FindVar,
24 /* SYNOPSIS */
25 AROS_LHA(CONST_STRPTR, name, D1),
26 AROS_LHA(ULONG , type, D2),
28 /* LOCATION */
29 struct DosLibrary *, DOSBase, 153, Dos)
31 /* FUNCTION
32 Finds a local variable structure.
34 INPUTS
35 name - the name of the variable you wish to find. Note that
36 variable names follow the same syntax and semantics
37 as filesystem names.
38 type - The type of variable to be found (see <dos/var.h>).
39 Actually, only the lower 8 bits of "type" are used
40 by FindVar().
42 RESULT
43 A pointer to the LocalVar structure for that variable if it was
44 found. If the variable wasn't found, or was of the wrong type,
45 NULL will be returned.
47 NOTES
49 EXAMPLE
51 BUGS
53 SEE ALSO
54 DeleteVar(), GetVar(), SetVar()
56 INTERNALS
57 For every local variable, a structure of type LocalVar exists:
58 struct LocalVar {
59 struct Node lv_Node;
60 UWORD lv_Flags;
61 UBYTE *lv_Value;
62 ULONG lv_Len;
65 lv_Node.ln_Type
66 holds the variable type, either LV_VAR for regular local environment
67 variables or LV_ALIAS for shell aliases. dos/var.h also defines
68 LVF_IGNORE (for private usage by the shell)
70 lv_Node.ln_Name
71 holds the variable name (NUL terminated string)
73 lv_Flags
74 stores GVF_BINARY_VAR and GVF_DONT_NULL_TERM if given as flags to
75 SetVar(). It is only used by GetVar().
77 lv_Value
78 holds the variable's value
80 lv_Len
81 is the length of lv_Value
83 *****************************************************************************/
85 AROS_LIBFUNC_INIT
87 /* Only the lowest 8 bits are valid here */
88 type &= 0xFF;
90 if (name != NULL)
92 /* We scan through the process->pr_LocalVars list */
93 struct Process *pr;
94 struct LocalVar *var;
96 pr = (struct Process *)FindTask(NULL);
97 ASSERT_VALID_PROCESS(pr);
98 var = (struct LocalVar *)pr->pr_LocalVars.mlh_Head;
100 ForeachNode(&pr->pr_LocalVars, var)
102 LONG res;
104 if (var->lv_Node.ln_Type == type)
106 /* The list is alphabetically sorted. */
107 res = Stricmp(name, var->lv_Node.ln_Name);
109 /* Found it */
110 if (res == 0)
112 return var;
115 /* We have gone too far through the sorted list. */
116 else if (res < 0)
118 break;
124 return NULL;
126 AROS_LIBFUNC_EXIT
127 } /* FindVar */