From a485084777db8a481b18642762318c497cf36c83 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 28 Apr 2011 20:38:39 +0200 Subject: [PATCH] Change struct empfile callback onresize() to return void ef_open() handles onresize() failing incorrectly. Instead of fixing that, drop the failure mode. It's not really used: unit_onresize() fails only when used incorrectly. It isn't. If it ever is, ignoring the failure is safe. --- include/file.h | 3 +-- include/unit.h | 2 +- src/lib/common/cargo.c | 5 ++--- src/lib/common/file.c | 20 ++++++++++---------- src/lib/subs/fileinit.c | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/include/file.h b/include/file.h index c5887efcc..47964a711 100644 --- a/include/file.h +++ b/include/file.h @@ -79,9 +79,8 @@ struct empfile { void (*prewrite)(int id, void *old, void *elt); /* * Called after table size changed, with file type as argument. - * Return -1 and set errno to make the operation fail. */ - int (*onresize)(int type); + void (*onresize)(int type); }; struct emptypedstr { diff --git a/include/unit.h b/include/unit.h index e7e37b298..06d082f02 100644 --- a/include/unit.h +++ b/include/unit.h @@ -52,7 +52,7 @@ extern int unit_cargo_first(int, int, int); extern int unit_cargo_next(int, int); extern int unit_cargo_count(int, int, int); extern int unit_nplane(int, int, int *, int *, int *); -extern int unit_onresize(int); +extern void unit_onresize(int); extern void unit_list(struct emp_qelem *); extern void unit_put(struct emp_qelem *list, natid actor); diff --git a/src/lib/common/cargo.c b/src/lib/common/cargo.c index 0152affc2..36df0b2d7 100644 --- a/src/lib/common/cargo.c +++ b/src/lib/common/cargo.c @@ -276,14 +276,14 @@ unit_cargo_init(void) * Return 0 on success, -1 on error. * This is the struct empfile onresize callback for units. */ -int +void unit_onresize(int type) { int n, i; struct clink *cl; if (CANT_HAPPEN(type < EF_SHIP || type > EF_NUKE)) - return -1; + return; n = ef_nelem(type); cl = realloc(clink[type], n * sizeof(*clink[type])); @@ -295,7 +295,6 @@ unit_onresize(int type) nclink[type] = n; if (ef_flags(type) & EFF_MEM) clink_check(type); - return 0; } /* diff --git a/src/lib/common/file.c b/src/lib/common/file.c index 388f8c6a5..c02afb373 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -150,8 +150,8 @@ ef_open(int type, int how, int nelt) } } - if (ep->onresize && ep->onresize(type) < 0) - return 0; + if (ep->onresize) + ep->onresize(type); return 1; } @@ -275,8 +275,8 @@ ef_close(int type) } ep->flags &= EFF_IMMUTABLE; ep->baseid = ep->cids = ep->fids = 0; - if (ep->onresize && ep->onresize(type) < 0) - retval = 0; + if (ep->onresize) + ep->onresize(type); return retval; } @@ -523,8 +523,8 @@ ef_write(int type, int id, void *from) if (id >= ep->fids) { /* write beyond end of file extends it, take note */ ep->fids = id + 1; - if (ep->onresize && ep->onresize(type) < 0) - return 0; + if (ep->onresize) + ep->onresize(type); } if (id >= ep->baseid && id < ep->baseid + ep->cids) { cachep = ep->cache + (id - ep->baseid) * ep->size; @@ -708,8 +708,8 @@ ef_extend(int type, int count) } } ep->fids = id + count; - if (ep->onresize && ep->onresize(type) < 0) - return 0; + if (ep->onresize) + ep->onresize(type); return 1; } @@ -801,8 +801,8 @@ ef_truncate(int type, int count) ep->cids = count - ep->baseid; } - if (ep->onresize && ep->onresize(type) < 0) - return 0; + if (ep->onresize) + ep->onresize(type); return 1; } diff --git a/src/lib/subs/fileinit.c b/src/lib/subs/fileinit.c index 7d3183d64..b670de435 100644 --- a/src/lib/subs/fileinit.c +++ b/src/lib/subs/fileinit.c @@ -44,7 +44,7 @@ struct fileinit { void (*oninit)(void *); void (*postread)(int, void *); void (*prewrite)(int, void *, void *); - int (*onresize)(int); + void (*onresize)(int); }; static struct fileinit fileinit[] = { -- 2.43.0