(ef_open): Implement EFF_STATIC.
(ef_open): Simplify dynamic buffer allocation.
This commit is contained in:
parent
e6145fa515
commit
71908018ec
1 changed files with 17 additions and 13 deletions
|
@ -96,24 +96,28 @@ ef_open(int type, int how)
|
||||||
ep->fids = fsiz / ep->size;
|
ep->fids = fsiz / ep->size;
|
||||||
|
|
||||||
/* allocate cache */
|
/* allocate cache */
|
||||||
if (CANT_HAPPEN(ep->flags & EFF_STATIC)) {
|
if (ep->flags & EFF_STATIC) {
|
||||||
/* not implemented */
|
/* ep->cache already points to space for e->csize elements */
|
||||||
ep->flags &= ~EFF_STATIC;
|
if (how & EFF_MEM) {
|
||||||
}
|
if (ep->fids > ep->csize) {
|
||||||
if (how & EFF_MEM)
|
logerror("Can't open %s: file larger than %d bytes",
|
||||||
ep->csize = ep->fids;
|
ep->file, ep->fids * ep->size);
|
||||||
else
|
close(fd);
|
||||||
ep->csize = max(1, blksize(fd) / ep->size);
|
return 0;
|
||||||
size = ep->csize * ep->size;
|
}
|
||||||
if (size) {
|
}
|
||||||
|
} else {
|
||||||
|
if (how & EFF_MEM)
|
||||||
|
ep->csize = ep->fids;
|
||||||
|
else
|
||||||
|
ep->csize = max(1, blksize(fd) / ep->size);
|
||||||
|
size = ep->csize * ep->size;
|
||||||
ep->cache = malloc(size);
|
ep->cache = malloc(size);
|
||||||
if (ep->cache == NULL) {
|
if (ep->cache == NULL && size) {
|
||||||
logerror("Can't open %s: out of memory", ep->file);
|
logerror("Can't open %s: out of memory", ep->file);
|
||||||
close(fd);
|
close(fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
ep->cache = NULL;
|
|
||||||
}
|
}
|
||||||
ep->baseid = 0;
|
ep->baseid = 0;
|
||||||
ep->cids = 0;
|
ep->cids = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue