Commit graph

110 commits

Author SHA1 Message Date
3e400c018c Update copyright notice. 2006-01-05 13:36:57 +00:00
c3900f8424 (empfile, fileinit, lnd_init, lnd_postread, lnd_prewrite, nuk_init)
(nuk_postread, nuk_prewrite, pln_init, pln_postread, pln_prewrite)
(sct_postread, sct_prewrite, shp_init, shp_postread, shp_prewrite)
(ef_extend): Use void * for generic pointer parameter.
2005-12-31 12:52:18 +00:00
3aebb68ee7 Include config.h. 2005-12-27 18:04:19 +00:00
803009d0ce (fillcache, do_write): Revert the previous revision. The portability
issue applies only to sockets, and EWOULDBLOCK isn't defined on all
systems.
2005-11-26 18:36:48 +00:00
edaa05b8cb (fillcache, do_write, io_input, io_output): Portability fix: always
check both EAGAIN and EWOULDBLOCK.  These are distinct on some
systems, e.g. HP-UX.
(io_output) [hpux]: Used to treat all errors as EWOULDBLOCK.  This
looks like a inept attempt to `fix' the above.  Remove.
2005-11-22 20:28:18 +00:00
661b650c1a (ef_write): Don't memcpy() onto itself; behavior's undefined. 2005-11-19 15:41:37 +00:00
d575d779ad (ef_ptr, ef_read): Undo rev. 1.52 for these two, because there are
callers that rely on these functions to fail for bad ID.
2005-11-19 11:20:13 +00:00
4fb17a62c0 (ef_init_chr): Sentinel names are now null, simplify sentinel check. 2005-11-07 07:54:16 +00:00
5173f8cd07 (ef_ptr, ef_read): Oops on bad ID. Some callers rely on these
functions to fail at the end of the table.  To support that, the first
ID beyond the end is not considered bad.

(ef_ensure_space): Oops on bad ID.
2005-11-06 11:01:37 +00:00
41bf5be715 (UNMAPPED_INIT, UNMAPPED_CACHE, ARRAY_INIT, ARRAY_TABLE, PTR_INIT)
(PTR_CACHE): Rename.

(ARRAY_CACHE): New.
(empfile): Use it to set csize of elements EF_SHIP_CHR, EF_PLANE_CHR,
EF_LAND_CHR, EF_NUKE_CHR.
(ef_init_chr): Now that empfile[]'s initializer sets csize, remove the
temporary csize initialization here.  The value wasn't correct, but
better than nothing.
2005-11-03 18:25:26 +00:00
ae9e7dad43 (ef_ptr): Null cache can't happen. 2005-10-31 21:26:16 +00:00
4cbb45d0e0 (ef_open): EFF_STATIC and cache not null can't happen.
(ef_open): Leave check of fd to do_write().
2005-10-30 18:48:55 +00:00
b2ae3257ca (empfile): Rename member ef_uid to uid for consistency with other
members.

(empfile): Reorder members for clearer documentation.

(EFF_IMMUTABLE): New.
(EFF_OPEN): Remove, use ~EFF_IMMUTABLE.

(empfile): Don't initialize member size to a useless value for EF_MAP
and EF_BMAP.  ef_init() writes the real value.
2005-10-30 12:50:13 +00:00
Ron Koenderink
bb79c64b92 (ef_init_chr): Add a NULL check to sentinel check. 2005-10-29 20:38:59 +00:00
6c849f0334 (ef_init): Fix check for sentinel. 2005-10-29 16:50:07 +00:00
ae81dade53 (ef_init, ef_init_srv): Rename old ef_init() ef_init_srv(), call new
ef_init().  Move initialization of map sizes to ef_init().
(main): Don't initialize map sizes by hand, call ef_init().

(fileinit): Internal linkage.
2005-10-29 15:16:50 +00:00
6be5ba5d40 (ef_byname): Old version didn't work when a table name was followed by
one of its prefixes.  src/lib/global/file.c rev. 1.18 added such table
entries, and file.h rev. 1.34 made them visible to ef_byname().
Simply use stmtch().  This also rejects ambiguous abbreviations: "s"
used to return EF_SECTOR, it now returns M_NOTUNIQUE.
2005-10-29 06:18:41 +00:00
2fc1e74a72 (ef_byname_from): New.
(set, mission, multifire, fuel, cons_choose, cede): Use it instead of
ef_byname().  Remove the hacks to map unwanted results to wanted
results.  The hacks in set() were broken: bad input made the code cast
arbitrary items to union trdgenstr, with potentially disastrous
consequences.  Closes #906483 and #906486.

(set): Less cryptic prompt and diagnostics.
2005-10-27 21:33:17 +00:00
71908018ec (ef_open): Implement EFF_STATIC.
(ef_open): Simplify dynamic buffer allocation.
2005-10-26 16:49:52 +00:00
babf467e15 (EFF_STATIC): New.
(empfile): Use it.
(ef_open): Oops on it (not implemented).
(ef_close): Implement it (trivial).
2005-10-24 23:35:18 +00:00
889dfebaad (ef_nameof, ef_ensure_space): Oops on bad argument.
(ef_check): Use CANT_HAPPEN().
2005-10-24 23:27:18 +00:00
12b1427693 (ef_zapcache): Clearing the cache doesn't make sense. No harm done if
the next user can't use the cache, it gets automatically zapped then.
Remove.
2005-10-24 23:23:53 +00:00
ecab7c4f2f (ef_read): Catch null cache.
(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.
2005-10-24 23:16:13 +00:00
880a3e399b (ef_extend): Use do_write() & simplify. Catch table not file-backed.
Catch negative count; used to have no effect with EFF_MEM, and
confusion otherwise.  Try to recover from partially successful
extension.  Need help from ef_write() to do a better job; to be done.
2005-10-24 22:47:16 +00:00
62264f8ada (ef_extend): Fix rev. 1.25. 2005-10-24 22:44:29 +00:00
e29369fadb Clean up rev. 1.30. 2005-10-24 21:57:20 +00:00
f2e6d6b232 (ef_ptr): Change return type to void *.
(ef_ptr): Use CANT_HAPPEN() to ensure EFF_MEM; check it before less
serious index out of range failure.
2005-10-24 21:43:47 +00:00
5030d124a1 (ef_open): Fix fatal typo. 2005-10-24 20:42:27 +00:00
8b6549519b (ef_open): Portability fix: malloc(0) may return null, which is not a
failure.  fillcache() chokes on null cache, so don't call it for empty
files.
2005-10-24 20:36:17 +00:00
3eb3607f0d (ef_open): Failed to reset empfile member fd on failure, and leaked
file descriptors.

(ef_flush, ef_close): Rely on negative fd instead of null cache to
detect unopened file.  This is more logical and consistent with the
use of cache by the new tables that are not file-backed (rev. 1.22).
Use CANT_HAPPEN().

(ef_close): Failed to report cash flush failure.

(ef_close): Clear all EFF_OPEN flags.  Should have been done in
rev. 1.27.
2005-10-24 20:18:04 +00:00
1c4fb67911 (do_write): New.
(ef_flush, ef_write): Use it.  Old code couldn't cope with interrupted
or short writes (mostly harmless, as disk reads commonly complete).

(ef_write): Use CANT_HAPPEN() for catching unimplemented table
extensions.
2005-10-24 19:17:05 +00:00
ab03d83ce1 (fillcache): Rewrite. Old version failed to check success of lseek(),
couldn't cope with interrupted or short reads (mostly harmless, as
disk reads commonly complete), and left an empty cache after a failed
read.
(ef_open): Use fillcache() instead of read().
(ef_read): Fail if fillcache() fails to read at least one element.
Old version copied garbage to its caller and claimed success.
2005-10-24 19:02:39 +00:00
3ea02e2519 (ef_open): Fail if file size is not a multiple of record size. 2005-10-24 18:40:13 +00:00
64d8f6babe (ef_open, EFF_RDONLY, EFF_CREATE, EFF_OPEN): Replace mode parameter
(really open flags, not mode) by new flags EFF_RDONLY, EFF_CREATE.
Open flags were needlessly general.  Callers changed.
(empfile): Member mode now unused, remove.
2005-10-24 18:18:59 +00:00
bfd14661c5 (ef_close): Reset member fd.
(ef_open): Catch attempt to open open file.
2005-10-23 06:24:08 +00:00
a3dd70f8c0 (EFF_OPEN): New.
(ef_open): Restrict HOW to EFF_OPEN.
2005-10-23 06:17:14 +00:00
290e759998 (ef_open): Remove code killed by the previous revision. 2005-10-22 19:59:56 +00:00
2802ce1863 (ef_open): Don't assume blksize() is the same for all files.
(ef_open): Ensure the cache has at least one slot.
2005-10-22 19:12:27 +00:00
0ab9260151 (empfile, chr_camap): Merge chr_camap[] into empfile[]. No existing
user sees the new elements of empfile[].
(EF_SECTOR_CHR, EF_SHIP_CHR, EF_PLANE_CHR, EF_LAND_CHR, EF_NUKE_CHR)
(EF_TREATY_CHR, EF_ITEM, EF_INFRASTRUCTURE, EF_PRODUCT): New.  Not yet
used.
(my_ef_byname): Replacement for ef_byname() that sees the new
elements.
(xdchr): Work with empfile[] instead of chr_camap[].
(xdump): Use my_ef_byname() instead of ef_byname() and
chridx_by_name().
(camap, chr_camap, chridx_by_name): Remove.
2005-10-21 19:38:37 +00:00
380b063f9c Remove some redundant parenthesis; no functional change. 2005-07-23 19:48:35 +00:00
a127869da2 (ef_write): Don't call log_last_commands() directly, use oops(). If
it's worth logging commands, then it's worth dumping core.
2005-05-28 15:52:29 +00:00
345ad3dfe0 Update copyright notice. 2005-03-16 22:03:16 +00:00
Ron Koenderink
55e6aca9e0 (wrmakesrc,wripglob,wrgamesdef,info,apro,mobupdate,rea,turn
upda,ef_open,logerror,emp_config,match_user,show_motd,gamedown,
typed_wu,delete_old_announcements,mobility_check,mobility_init,
allocate_memory,write_newcap_script,main,files,fairland,doconfig,)
[_WIN32]: Switchback to default mode of text.
"t" (text) is not included the ISO/ANSI C standard but "b" (binary)
is included.
2005-03-02 12:47:15 +00:00
Ron Koenderink
1a8488bc45 (main,mobility_check,upda,turn,rea,mobupdate,ef_open,logerror,
emp_config,gamedown,show_motd,match_user,typed_wu,
delete_old_announcements) [_WIN32]: switch the default file mode to
binary to match POSIX.  Remove the now unneccessary ifdef for
the open/fopen. Add text mode for user files (econfig/auth).
2004-12-30 01:31:03 +00:00
Marc Olzheim
d3396821f0 (ef_extend): free allocated tmpobj before early returns as well. 2004-12-16 12:29:41 +00:00
Marc Olzheim
e94b16b024 (EFF_COM,ef_items): No longer in use after removal of 'variables'. Removed.
Clean 'register' and s_char on the way. Remove dead code.
Rename some variables to better reflect their meaning.
Add function comments.
2004-12-16 12:25:56 +00:00
Marc Olzheim
c6ef918f3a Cleanup #includes of (mostly a long time) unused header files.
No functional changes.
2004-12-13 16:47:13 +00:00
7d34832100 (fldoff): Use offsetof() instead. Rest of struct.h is unused, remove. 2004-09-10 18:41:58 +00:00
fac342ed49 Update copyright notice. 2004-09-07 15:07:16 +00:00
dcfd251f95 caddr_t is obsolete. Replace by void *, except for struct empfile
member cache, which becomes char * to keep pointer arithmetic simple.
2004-08-23 18:29:44 +00:00