diff --git a/include/file.h b/include/file.h index cf20114f..f6ea83bb 100644 --- a/include/file.h +++ b/include/file.h @@ -102,6 +102,7 @@ extern int ef_close(int); extern int ef_flush(int); extern int ef_write(int, int, caddr_t); extern int ef_extend(int, int); +extern int ef_ensure_space(int, int, int); extern void ef_zapcache(int); extern int ef_nelem(int); extern int ef_flags(int); diff --git a/src/lib/commands/edit.c b/src/lib/commands/edit.c index 3575d21d..7c0b2972 100644 --- a/src/lib/commands/edit.c +++ b/src/lib/commands/edit.c @@ -210,6 +210,8 @@ edit(void) case 's': if ((err = doship(thing[0], arg, ptr, &ship)) != RET_OK) return err; + if (!ef_ensure_space(EF_SHIP, ship.shp_uid, 50)) + return RET_FAIL; if (!putship(ship.shp_uid, &ship)) return RET_FAIL; break; @@ -217,6 +219,8 @@ edit(void) if ((err = dounit(thing[0], arg, ptr, &land)) != RET_OK) return err; + if (!ef_ensure_space(EF_LAND, land.lnd_uid, 50)) + return RET_FAIL; if (!putland(land.lnd_uid, &land)) return RET_FAIL; break; @@ -224,6 +228,8 @@ edit(void) if ((err = doplane(thing[0], arg, ptr, &plane)) != RET_OK) return err; + if (!ef_ensure_space(EF_PLANE, plane.pln_uid, 50)) + return RET_FAIL; if (!putplane(plane.pln_uid, &plane)) return RET_FAIL; break; diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 1418657a..c0b58062 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -474,3 +474,13 @@ ef_check(int type) } return 0; } + +int +ef_ensure_space(int type, int id, int count) +{ + while (id >= empfile[type].fids) { + if (!ef_extend(type, count)) + return 0; + } + return 1; +}