extern void ef_set_uid(int, void *, int);
extern int ef_extend(int, int);
extern int ef_ensure_space(int, int, int);
+extern int ef_id_limit(int);
extern int ef_truncate(int, int);
extern int ef_nelem(int);
extern int ef_flags(int);
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
}
return 1;
}
+
+/*
+ * Return maximum ID acceptable for table TYPE.
+ * Assuming infinite memory and disk space.
+ */
+int
+ef_id_limit(int type)
+{
+ struct empfile *ep;
+
+ if (ef_check(type) < 0)
+ return -1;
+ ep = &empfile[type];
+ if (ep->nent >= 0)
+ return ep->nent - 1;
+ if (ep->flags & EFF_MEM) {
+ if (ep->flags & EFF_STATIC)
+ return ep->csize - 1 - ((ep->flags & EFF_SENTINEL) != 0);
+ }
+ return INT_MAX;
+}
getobj(void)
{
struct empfile *ep = &empfile[cur_type];
+ int max_id;
if (!cur_obj) {
cur_obj_is_blank = cur_id >= ep->fids;
if (cur_obj_is_blank) {
- if (ef_ensure_space(cur_type, cur_id, 1))
+ max_id = ef_id_limit(cur_type);
+ if (cur_id > max_id)
+ gripe("Can't put ID %d into table %s, it holds only 0..%d",
+ cur_id, ep->name, max_id);
+ else if (!ef_ensure_space(cur_type, cur_id, 1))
+ gripe("Can't put ID %d into table %s",
+ cur_id, ep->name);
+ else
cur_obj = ef_ptr(cur_type, cur_id);
- /* FIXME diagnose out of dynamic memory vs. static table full */
- if (!cur_obj)
- gripe("Can't put ID %d into table %s, it holds only 0..%d.",
- cur_id, ep->name, ep->fids - 1);
} else
cur_obj = ef_ptr(cur_type, cur_id);
}