Indentation fix, cleanup.
[AROS.git] / rom / dos / deletevar.c
blob66c50e0c34d0054c98f10169b1b0b17a184f9214
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: DeleteVar() - Deletes a local or environmental variable.
6 Lang: english
7 */
8 #include "dos_intern.h"
9 #include <proto/exec.h>
11 /*****************************************************************************
13 NAME */
14 #include <dos/var.h>
15 #include <proto/dos.h>
17 AROS_LH2(LONG, DeleteVar,
19 /* SYNOPSIS */
20 AROS_LHA(CONST_STRPTR, name, D1),
21 AROS_LHA(ULONG , flags, D2),
23 /* LOCATION */
24 struct DosLibrary *, DOSBase, 152, Dos)
26 /* FUNCTION
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 environment variable otherwise.
32 A global environment variable will only be deleted for the
33 type LV_VAR.
35 INPUTS
36 name - the name of the variable to delete. Note that variable
37 names follow the same syntax and semantics as filesystem
38 names.
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 environment variable.
47 RESULT
48 If non-zero, the variable was deleted successfully,
49 DOSFALSE otherwise.
51 NOTES
52 When the GVF_SAVE_VAR flag is set, and only one of the global
53 variable pair could be deleted (either the in memory or on disk
54 variable), DOSFALSE will be returned.
56 EXAMPLE
58 BUGS
60 SEE ALSO
62 INTERNALS
63 XXX: Find out whether GVF_SAVE_VAR does actually affect this function.
65 *****************************************************************************/
67 AROS_LIBFUNC_INIT
69 if(name)
71 if((flags & GVF_GLOBAL_ONLY) == 0)
73 struct LocalVar *lv = NULL;
74 lv = FindVar(name, flags & 0xFF);
75 if(lv)
77 /* free allocated memory for value of variable */
78 FreeMem(lv -> lv_Value, lv -> lv_Len);
80 Remove((struct Node *)lv);
81 FreeVec(lv);
82 return DOSTRUE;
84 } /* !global only => local variable */
86 /* If we are allowed to delete globals, and not deleting an alias */
87 if( ((flags & GVF_LOCAL_ONLY) == 0) && ((flags & 0x7F) == 0) )
89 /* Variable names should be less than 256 characters. */
90 /* as a standard: look for the file in ENV: if no path is
91 given in the variable
93 UBYTE filebuffer[256] = "ENV:";
94 BPTR filelock;
95 BOOL delMemory = FALSE, delDisk = FALSE;
97 AddPart(filebuffer, name, 256);
99 if((filelock = Lock(filebuffer, EXCLUSIVE_LOCK)))
101 UnLock(filelock);
102 delMemory = DeleteFile(filebuffer);
105 if(flags & GVF_SAVE_VAR)
107 filebuffer[0] = 0;
108 AddPart(filebuffer, "ENVARC:", 256);
109 AddPart(filebuffer, name, 256);
111 if((filelock = Lock(filebuffer, EXCLUSIVE_LOCK)))
113 UnLock(filelock);
114 delDisk = DeleteFile(filebuffer);
117 else delDisk = TRUE;
119 if( (delDisk != FALSE) && (delMemory != FALSE))
120 return TRUE;
121 } /* !local only => Global variable */
122 } /* if(name) */
124 return DOSFALSE;
126 AROS_LIBFUNC_EXIT
127 } /* DeleteVar */