1 #include "csf.h"
2 #include "csfimpl.h"
3
4 /* read an attribute (LIBRARY_INTERNAL)
5 * MgetAttribute reads an attribute if it is available.
6 * Be aware that you can't pass a simple pointer to some
7 * (array of) structure(s) due to alignment en endian problems.
8 * At some time there will be a separate get function for each attribute
9 * returns 0 if the attribute is not found, arg id if
10 * the attribute is found.
11 */
CsfGetAttribute(MAP * m,CSF_ATTR_ID id,size_t elSize,size_t * nmemb,void * attr)12 CSF_ATTR_ID CsfGetAttribute(
13 MAP *m, /* map handle */
14 CSF_ATTR_ID id, /* id of attribute to be read */
15 size_t elSize, /* size of each data-element */
16 size_t *nmemb, /* write-only. How many elSize members are read. */
17 void *attr) /* write-only. buffer where attribute is read in.
18 * Must be big enough to hold buffer.
19 */
20 {
21 ATTR_CNTRL_BLOCK b;
22 CSF_FADDR pos;
23 PRECOND(CsfValidSize(elSize));
24 CHECKHANDLE_GOTO(m, error);
25
26 if (! READ_ENABLE(m))
27 {
28 M_ERROR(NOACCESS);
29 goto error;
30 }
31
32 if (CsfGetAttrBlock(m, id, &b) != 0)
33 {
34 int i = CsfGetAttrIndex(id, &b);
35 *nmemb = b.attrs[i].attrSize;
36 POSTCOND( ((*nmemb) % elSize) == 0);
37 *nmemb /= elSize;
38 POSTCOND( (*nmemb) > 0);
39 pos = b.attrs[i].attrOffset;
40 (void)csf_fseek(m->fp, pos, SEEK_SET);
41 m->read(attr,elSize, (size_t)(*nmemb),m->fp);
42 return(id);
43 }
44 else
45 *nmemb = 0;
46 error: return(0); /* not available or an error */
47 } /* MgetAttribute */
48