]> git.pond.sub.org Git - empserver/commitdiff
(ef_read): Catch null cache.
authorMarkus Armbruster <armbru@pond.sub.org>
Mon, 24 Oct 2005 23:16:13 +0000 (23:16 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Mon, 24 Oct 2005 23:16:13 +0000 (23:16 +0000)
(ef_read): Used to get the file size again some circumstances; doesn't
make sense, as no other process may be writing this file.

(ef_write): Don't refuse to write beyond record 65536.  This module
can cope with that.  Some users have trouble long before that (short
record numbers), but that should be handled there.

(ef_write): Catch table not file-backed.

src/lib/common/file.c

index 224be2ba28324a61259cbd5e4754735c321a7b9f..0b924ebc82c03bd3dc1c0ed3b46a783b17be2f91 100644 (file)
@@ -178,7 +178,6 @@ ef_ptr(int type, int id)
 
     if (ef_check(type) < 0)
        return NULL;
-
     ep = &empfile[type];
     if (CANT_HAPPEN(!(ep->flags & EFF_MEM)))
        return NULL;
@@ -200,21 +199,20 @@ ef_read(int type, int id, void *into)
     if (ef_check(type) < 0)
        return 0;
     ep = &empfile[type];
+    if (CANT_HAPPEN(!ep->cache))
+       return 0;
     if (id < 0)
+       return 0;               /* FIXME can this happen? */
+    if (id >= ep->fids)
        return 0;
+
     if (ep->flags & EFF_MEM) {
-       if (id >= ep->fids)
-           return 0;
-       from = ep->cache + (id * ep->size);
+       from = ep->cache + id * ep->size;
     } else {
-       if (id >= ep->fids) {
-           ep->fids = fsize(ep->fd) / ep->size;
-           if (id >= ep->fids)
-               return 0;
-       }
-       if (ep->baseid + ep->cids <= id || ep->baseid > id)
+       if (ep->baseid + ep->cids <= id || ep->baseid > id) {
            if (fillcache(ep, id) < 1)
                return 0;
+       }
        from = ep->cache + (id - ep->baseid) * ep->size;
     }
     memcpy(into, from, ep->size);
@@ -318,11 +316,8 @@ ef_write(int type, int id, void *from)
     if (ef_check(type) < 0)
        return 0;
     ep = &empfile[type];
-    if (id > 65536) {
-       /* largest unit id; this may bite us in large games */
-       logerror("ef_write: type %d id %d is too large!\n", type, id);
+    if (CANT_HAPPEN(ep->fd < 0))
        return 0;
-    }
     if (ep->prewrite)
        ep->prewrite(id, from);
     if (CANT_HAPPEN((ep->flags & EFF_MEM) ? id >= ep->fids : id > ep->fids))