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.
This commit is contained in:
Markus Armbruster 2011-04-28 20:38:39 +02:00
parent 45c7337e70
commit a485084777
5 changed files with 15 additions and 17 deletions

View file

@ -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 {

View file

@ -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);

View file

@ -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;
}
/*

View file

@ -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;
}

View file

@ -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[] = {