2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: DeleteVar() - Deletes a local or environmental variable.
8 #include "dos_intern.h"
9 #include <proto/exec.h>
11 /*****************************************************************************
15 #include <proto/dos.h>
17 AROS_LH2(LONG
, DeleteVar
,
20 AROS_LHA(CONST_STRPTR
, name
, D1
),
21 AROS_LHA(ULONG
, flags
, D2
),
24 struct DosLibrary
*, DOSBase
, 152, Dos
)
27 Deletes a local or environment variable.
29 The default is to delete a local variable if one was found,
30 or to delete a global environmental variable otherwise.
32 A global environmental variable will only be deleted for the
36 name - the name of the variable to delete. Note that variable
37 names follow the same syntax and semantics as filesystem
40 flags - A combination of the type of variable (low 8 bits), and
41 flags to control the behaviour of this routine.
42 Currently defined flags:
44 GVF_LOCAL_ONLY - delete a local variable.
45 GVF_GLOBAL_ONLY - delete a global environmental variable.
49 If non-zero, the variable was deleted successfully,
53 When the GVF_SAVE_VAR flag is set, and only one of the global
54 variable pair could be deleted (either the in memory or on disk
55 variable), DOSFALSE will be returned.
64 XXX: Find out whether GVF_SAVE_VAR does actually effect this function.
66 *****************************************************************************/
69 AROS_LIBBASE_EXT_DECL(struct DosLibrary
*,DOSBase
)
73 if((flags
& GVF_GLOBAL_ONLY
) == 0)
75 struct LocalVar
*lv
= NULL
;
76 lv
= FindVar(name
, flags
& 0xFF);
79 /* free allocated memory for value of variable */
80 FreeMem(lv
-> lv_Value
, lv
-> lv_Len
);
82 Remove((struct Node
*)lv
);
86 } /* !global only => local variable */
88 /* If we are allowed to delete globals, and not deleting an alias */
89 if( ((flags
& GVF_LOCAL_ONLY
) == 0) && ((flags
& 0x7F) == 0) )
91 /* Variable names should be less than 256 characters. */
92 /* as a standard: look for the file in ENV: if no path is
95 UBYTE filebuffer
[256] = "ENV:";
97 BOOL delMemory
= FALSE
, delDisk
= FALSE
;
99 AddPart(filebuffer
, name
, 256);
101 if((filelock
= Lock(filebuffer
, EXCLUSIVE_LOCK
)))
104 delMemory
= DeleteFile(filebuffer
);
107 if(flags
& GVF_SAVE_VAR
)
110 AddPart(filebuffer
, "ENVARC:", 256);
111 AddPart(filebuffer
, name
, 256);
113 if((filelock
= Lock(filebuffer
, EXCLUSIVE_LOCK
)))
116 delDisk
= DeleteFile(filebuffer
);
121 if( (delDisk
!= FALSE
) && (delMemory
!= FALSE
))
123 } /* !local only => Global variable */