]> git.pond.sub.org Git - empserver/commitdiff
(ef_open): Implement EFF_STATIC.
authorMarkus Armbruster <armbru@pond.sub.org>
Wed, 26 Oct 2005 16:49:52 +0000 (16:49 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 26 Oct 2005 16:49:52 +0000 (16:49 +0000)
(ef_open): Simplify dynamic buffer allocation.

src/lib/common/file.c

index a45e14011b24dc9a5182316a7d6835bd8ce0246f..a1a4b975e1f50d7d91da1ee5d0911a68a2b81362 100644 (file)
@@ -96,24 +96,28 @@ ef_open(int type, int how)
     ep->fids = fsiz / ep->size;
 
     /* allocate cache */
-    if (CANT_HAPPEN(ep->flags & EFF_STATIC)) {
-       /* not implemented */
-       ep->flags &= ~EFF_STATIC;
-    }
-    if (how & EFF_MEM)
-       ep->csize = ep->fids;
-    else
-       ep->csize = max(1, blksize(fd) / ep->size);
-    size = ep->csize * ep->size;
-    if (size) {
+    if (ep->flags & EFF_STATIC) {
+       /* ep->cache already points to space for e->csize elements */
+       if (how & EFF_MEM) {
+           if (ep->fids > ep->csize) {
+               logerror("Can't open %s: file larger than %d bytes",
+                        ep->file, ep->fids * ep->size);
+               close(fd);
+               return 0;
+           }
+       }
+    } 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);
-       if (ep->cache == NULL) {
+       if (ep->cache == NULL && size) {
            logerror("Can't open %s: out of memory", ep->file);
            close(fd);
            return 0;
        }
-    } else {
-       ep->cache = NULL;
     }
     ep->baseid = 0;
     ep->cids = 0;