Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / nonvolatile / nvdisk / writenvddata.c
blobf563a6b5595bc91b492659da24df4de9d61a3a5f
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /*****************************************************************************
11 NAME */
13 #include "nvdisk_intern.h"
14 #include <dos/dos.h>
15 #include <proto/dos.h>
16 #include <libraries/nonvolatile.h>
19 AROS_LH4(LONG, WriteNVDData,
21 /* SYNOPSIS */
23 AROS_LHA(STRPTR, appName, A0),
24 AROS_LHA(STRPTR, itemName, A1),
25 AROS_LHA(APTR, data, A2),
26 AROS_LHA(LONG, length, A3),
28 /* LOCATION */
30 struct Library *, nvdBase, 6, NVDisk)
32 /* FUNCTION
34 Write data to the nonvolatile memory.
36 INPUTS
38 appName -- the name of the application owning the data
39 itemName -- the name of the data to write
40 data -- the data to write
41 length -- the size of the data in bytes
43 RESULT
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
53 nonvolatile.library/StoreNV()
55 INTERNALS
57 HISTORY
59 November 2000, SDuvan -- implemeneted
61 ******************************************************************************/
64 AROS_LIBFUNC_INIT
66 LONG retval = 0;
67 BPTR oldCDir = CurrentDir(GPB(nvdBase)->nvd_location);
68 BPTR lock = Lock(appName, SHARED_LOCK);
69 BPTR file;
71 if(lock == BNULL)
73 lock = CreateDir(appName);
75 if(lock == BNULL)
77 LONG err = IoErr();
78 if(err == ERROR_WRITE_PROTECTED ||
79 err == ERROR_DISK_WRITE_PROTECTED)
80 return NVERR_WRITEPROT;
81 else
82 return NVERR_FAIL;
86 /* 'lock' is now containing a valid lock on the 'appName' directory. */
88 CurrentDir(lock);
90 file = Open(itemName, MODE_NEWFILE);
92 if(file == BNULL)
94 UnLock(lock);
95 CurrentDir(oldCDir);
96 return NVERR_FAIL;
99 if(Write(file, data, length) == -1)
101 retval = NVERR_FATAL;
104 Close(file);
105 UnLock(lock);
106 CurrentDir(oldCDir);
108 return retval;
110 AROS_LIBFUNC_EXIT
111 } /* WriteData */