--- freem/src/global_bltin.c 2025/04/08 21:41:13 1.11 +++ freem/src/global_bltin.c 2025/04/09 00:43:07 1.12 @@ -1,5 +1,5 @@ /* - * $Id: global_bltin.c,v 1.11 2025/04/08 21:41:13 snw Exp $ + * $Id: global_bltin.c,v 1.12 2025/04/09 00:43:07 snw Exp $ * freem database engine * * @@ -24,6 +24,9 @@ * along with FreeM. If not, see . * * $Log: global_bltin.c,v $ + * Revision 1.12 2025/04/09 00:43:07 snw + * Exit with fatal error if a header mismatch found + * * Revision 1.11 2025/04/08 21:41:13 snw * Make insert, update, and splitp global handler functions take a ptr to a global_handle instead of a file descriptor * @@ -294,7 +297,7 @@ int gbl_write_header(global_handle *g, g if (g->opened == FALSE) { return FALSE; } - + gbl_lock (g, 1); old_position = lseek (g->fd, 0, SEEK_CUR); lseek (g->fd, 0, SEEK_SET); @@ -306,6 +309,8 @@ int gbl_write_header(global_handle *g, g lseek (g->fd, old_position, SEEK_SET); gbl_unlock (g); + + gbl_read_header (g, &g->header); return TRUE; } /* gbl_write_header() */ @@ -383,7 +388,6 @@ int gbl_create(global_handle *g) short gbl_open(global_handle *g, short action) { int result; - global_header h; if (g->opened == FALSE) { while (1) { @@ -414,13 +418,29 @@ short gbl_open(global_handle *g, short a } else { g->opened = TRUE; - result = gbl_read_header (g, &h); - + result = gbl_read_header (g, &g->header); + if (result == GBL_HDR_OK) { g->opened = TRUE; } - else { - gbl_close (g); + else { + gbl_close (g); + set_io (UNIX); + + switch (result) { + + case GBL_HDR_BADMAGIC: + fprintf (stderr, "gbl_open: bad magic value in %s [FATAL]\n", g->global_name); + exit (1); + break; + + case GBL_HDR_BADVERSION: + fprintf (stderr, "gbl_open: global version is %d in %s (must be %d) [FATAL]\n", g->header.format_version, g->global_name, GBL_FORMAT_VERSION); + exit (1); + break; + + } + return FALSE; } }