Commit graph

143 commits

Author SHA1 Message Date
570ce80edf Fix fillcache() and do_write() error handling
Fix test for interrupted I/O.  Catch read hitting EOF unexpectedly.
Log errors in more detail.
2008-03-21 09:13:04 +01:00
0dd6702df1 Update known contributors comments 2008-03-14 20:25:44 +01:00
f33b96b1d1 Set timestamp automatically on write
Do it in do_write().  Remove the setting of timestamps elsewhere.

This fixes empdump to set timestamps to the current time instead of
zero on import.
2008-03-14 20:25:43 +01:00
cf16c74a3d New ef_truncate() 2008-03-14 20:25:10 +01:00
99594c1898 Oops when bad ef_type or uid is written to disk 2008-03-14 20:25:08 +01:00
c21c4ff9a7 New ef_blank()
It performs the same initialization as ef_extend().
2008-03-05 22:48:24 +01:00
a71f01585f empfile's init callback is now unused, remove 2008-03-05 22:48:24 +01:00
6cd3d55c4e Initialize ef_type and uid automatically in ef_extend()
New struct emptypedstr to avoid depending on empobj.h there.

Remove now superfluous manual initializations elsewhere.

This doesn't fix any missing initializations.
2008-03-05 22:48:23 +01:00
2eb8672b5e Generalize ef_extend() to non-file-backed tables
ef_extend() extended the file bypassing the cache, which screws up the
cache if it's EFF_MEM.  It fixed that by closing and reopening the
table.  Cheesy, and worked only for file-backed tables.

Rewrite ef_extend() to remap the cache properly for EFF_MEM.  While
there, simplify the !EFF_MEM case: steal a cache slot instead of
allocating a buffer.

Factor cache mapping out of ef_open() and ef_extend() into new
ef_realloc_cache().
2008-02-26 21:07:55 +01:00
f8dcb7b07b Replace EFF_RDONLY by EFF_PRIVATE
Read-only was a bit of a misnomer: you could write to the table by
obtaining a pointer into it from ef_ptr(), you just couldn't write to
the backing file.

Semantic changes:

* ef_flush() is now allowed when the table is file-backed or privately
  mapped.  Before, it had to be file-backed.  Flushing a privately
  mapped table does nothing, just like flushing a read-only table did.

* ef_write() is now allowed when the table is file-backed or fully
  cached.  Before, it had to be file-backed and not read-only.
  Writing to a privately mapped file-backed table doesn't write to the
  file.

* ef_extend() is not implemented for privately mapped tables, just
  like it wasn't implemented for read-only tables.
2008-02-26 20:40:59 +01:00
ef71897051 Remove obsolete comment
Obsolete since ef_open() locks the file (commit de124108).
2008-02-26 20:40:59 +01:00
55ff4f8e3a Clean up initialization of empfile[]
Split ef_init() into two functions: empfile_init() for initialization,
and empfile_fixup() to fix it up for configuration.  Put them next to
empfile[].  Move the call to empfile_init() from behind emp_config()
to before it.
2008-02-10 11:40:57 +01:00
db02dda32f Update copyright notice 2008-01-19 10:15:37 +01:00
404095d2fa Trim system includes. 2007-08-18 17:03:14 +00:00
Ron Koenderink
4bbc3f4286 Simple POSIX I/O emulation layer to work around Windows's defective
Unix I/O:
[_WIN32] (socklen_t, accept, posix_accept, bind. posix_bind, listen)
(posix_listen, setsockopt, posix_setsockopt, shutdown, posix_shutdown)
(socket, posix_socket, close, posix_close, creat, fstat, posix_fstat)
(lseek, posix_lseek, open, posix_open, read, posix_read, write)
(posix_write, fileno, posix_fileno, fcntl, O_NONBLOCK, F_RDLCK)
(F_WRLCK, F_GETFL, F_SETFL, F_SETLK, EWOULDBLOCK, ENOTSOCK)
(flock, fsync, posix_fsync):
New.
(ef_open, io_close, io_input, io_output, io_shutdown, io_noblocking)
(player_accept): Use them to simplify.
[_WIN32] (posix_fd2socket): New.
(empth_select): Use it.
(gen_power): Use it.
2007-08-14 03:33:28 +00:00
e1926d9ce9 (ef_open): Leaked file descriptor when fcntl() failed. 2007-07-31 05:03:25 +00:00
56de7a2151 (WORLD_SZ): New.
(isok, ef_init, bmaps_intersect, bp_init, player_accept)
(finish_sects, main): Use it.

(bp_neighbors, bp_lbcost, pathcost): Use XYOFFSET().  No
functional change.
2007-07-28 12:12:17 +00:00
Ron Koenderink
c97d79c0ee (add, disa, ef_open, logerror, main): Switch permissions to
standard defines instead of magic numbers to improve portability.
Also define WIN32 equivalents to the standard defines.
2007-03-10 16:29:51 +00:00
Ron Koenderink
7356da4775 (add.c, disa.c, log.c, new.c, wantupd.c, wu.c) [_WIN32,__GNUC__]:
Remove the !defined(__GNUC__) for <io.h>.
Not required for VC8.
2007-02-23 22:35:50 +00:00
7db3523f62 Update known contributors comment. 2007-01-13 10:16:43 +00:00
63bdc89835 Update copyright notice. 2007-01-09 19:09:31 +00:00
Ron Koenderink
ce63991c9f (ef_open) [_WIN32]: Fix to get a read lock instead of a write lock for
EFF_RDONLY and to get a write lock instead of a total file lock for
file opened for writing.
2006-11-29 12:16:43 +00:00
Ron Koenderink
2742a2db62 (ef_open) [_WIN32]: Add shared.h for MinGW environment,
needed for WIN32 file locking. Broken (missed) in rev 1.70.
2006-08-08 22:43:18 +00:00
Ron Koenderink
a89e21037e (ef_open) [_WIN32]: Provide file locking for WIN32. 2006-08-07 17:15:04 +00:00
de124108de (ef_open): Lock the file. This prevents two programs (servers in
particular) running on the same game state.  fairland does not use
ef_open() at this time, and thus ignores the lock.
2006-08-02 18:05:04 +00:00
Ron Koenderink
d413884a37 [_WIN32, __GNUC__]: Reorganize the include files for WIN32 to
separate the MinGW environment from the MSVC environment and
WIN32 environment.  Reorganize the order of the includes so
the system files are always loaded first to prevent with misc.h defines.
Remove system file includes from misc.h.
2006-07-13 21:14:16 +00:00
Ron Koenderink
e55198f2c3 [_WIN32]: Add missing include sys/types.h to get off_t. 2006-07-11 03:16:02 +00:00
e42053d928 Break inclusion cycle: prototypes.h and commands.h included each
other.  Ensure headers in include/ can be included in any order
(except for econfig-spec.h, which is special).  New header types.h to
help avoid inclusion cycles.  Sort include directives.  Remove some
superflous includes.
2006-07-10 06:37:23 +00:00
211a56489b (ef_open): Zero cache size (empty EFF_MEM file) can lead to null cache
on some systems, which confuses assertions.  Force non-zero size.
2006-03-06 18:23:41 +00:00
6bd0eabb21 (ef_init): Remove superflous size initialization for tables that are
initialized from builtin config files.
(ef_init_chr): Unused, remove.
2006-02-19 17:07:04 +00:00
4ff857507e Doc fix. 2006-02-12 23:01:47 +00:00
4515b84c59 COPYING duplicates information from README. Remove. Move GPL from
LICENSE to COPYING, because that's where it usually is.  Update all
the references to these files.
2006-01-21 19:48:41 +00:00
Ron Koenderink
04a8b84592 (ship_bomb, deli, do_demo, fuel, grin, look_ship)
(ltend, multifire, quite_bigdef, mine, landmine)
(do_loan, prod, printdiff, sell, sona, stre)
(tend, fire_dchrg, vers, work, ac_planedamage)
(ac_shipflak, ask_off, get_mine_dsupport, att_fight)
(ask_move_in_off, detonate, sd, land_gun)
(land_unitgun, lnd_fort_interdiction, lnd_fortify)
(perform_mission, pln_mine, pln_mobcost)
(retreat_ship1, retreat_land1, shp_sweep)
(shp_fort_interdiction, shp_missle_defense)
(new_work, growfood, upd_land, land_repair)
(get_materials, do_mob_ship, do_mob_land)
(load_it, unload_it, prod_plane, produce)
(guerrilla, upd_buildeff, spread_fallout)
(upd_ship, ship_repair, min, dmin, MIN):
Remove min() and dmin() functions and replace
with a MIN macro in misc.h.  Remove local MIN
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.

(fuel, look_ship, multifire, mission, sona)
(plane_sona, ef_open, player_accept, player_main)
(ac_dog, att_get_combat, calc_mobcost)
(ask_move_in_off, intelligence_report)
(build_mission_list_type, perform_mission)
(show_mission, use_supply, dodistribute)
(allocate_memory, max, dmax, MAX):
Remove max() and dmax() functions and replace
with a MAX macro in misc.h.  Remove local MAX
macros and use the new one in misc.h.  This
change removes the need for the special
case for _WIN32.
2006-01-12 14:23:55 +00:00
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