Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / nonvolatile / nvdisk / readnvddata.c
blobe2de989346b6c0521ac531194714a47e2a328e2a
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 <dos/dosextens.h>
16 #include <proto/dos.h>
17 #include <proto/exec.h>
18 #include <exec/memory.h>
21 AROS_LH2(APTR, ReadNVDData,
23 /* SYNOPSIS */
25 AROS_LHA(STRPTR, appName, A0),
26 AROS_LHA(STRPTR, itemName, A1),
28 /* LOCATION */
30 struct Library *, nvdBase, 5, NVDisk)
32 /* FUNCTION
34 Read the nv data corresponding to appname, itemname.
36 INPUTS
38 appname -- the name of the application owning the data
39 itemname -- the name of the data to retrieve
41 RESULT
43 A pointer to the data read. If something went wrong NULL is returned.
45 NOTES
47 EXAMPLE
49 BUGS
51 SEE ALSO
53 INTERNALS
55 HISTORY
57 November 2000, SDuvan -- implemented
59 ******************************************************************************/
62 AROS_LIBFUNC_INIT
64 APTR mem = NULL;
65 BPTR lock, lock2;
66 BPTR oldCDir;
68 /* Allocate a FileInfoBlock to be able to determine the size of the
69 file containing the data. */
70 struct FileInfoBlock *fib = AllocDosObject(DOS_FIB, NULL);
72 if(fib != NULL)
74 oldCDir = CurrentDir(GPB(nvdBase)->nvd_location);
75 lock = Lock(appName, SHARED_LOCK);
77 if(lock)
79 CurrentDir(lock);
81 lock2 = Lock(itemName, SHARED_LOCK);
83 if(lock2 != BNULL)
85 // We have now found the file -- check how big it is
86 Examine(lock2, fib);
88 mem = AllocVec(fib->fib_Size, MEMF_ANY);
90 if(mem != NULL)
92 if(Read(lock2, mem, fib->fib_Size) != fib->fib_Size)
94 FreeVec(mem);
95 mem = NULL;
98 } /* if(mem) */
100 UnLock(lock2);
102 } /* if(lock2) */
104 CurrentDir(oldCDir);
105 UnLock(lock);
107 } /* if(lock) */
109 CurrentDir(oldCDir);
110 FreeDosObject(DOS_FIB, fib);
112 } /* if(fib) */
114 return mem;
116 AROS_LIBFUNC_EXIT
117 } /* ReadData */