Commit 0d56fc75 authored by Kevin Bracey's avatar Kevin Bracey
Browse files

Do MessageTrans_CloseFile on exit, for safety's sake.

parent 782f8778
......@@ -36,6 +36,7 @@
* cannot be opened.
* 10-Dec-91 ECN Changed to use RISC_OSLibrary$Path again.
* 23-Mar-92 ECN Reverted to old messages lookup scheme.
* 16-Jun-97 KJB Close messages file on exit, for safety's sake.
*/
#include <stdlib.h>
......@@ -57,6 +58,14 @@ typedef struct msgs_block {
static msgs_block main_msgs_block;
static msgs_block default_msgs_block;
static void __msgs_closefiles(void)
{
if (main_msgs_block.lines)
_swix(MessageTrans_CloseFile, _IN(0), &main_msgs_block.cb);
if (default_msgs_block.lines)
_swix(MessageTrans_CloseFile, _IN(0), &default_msgs_block.cb);
}
static void __msgs_readfile(char *name, msgs_block *mb)
{
char *data;
......@@ -71,10 +80,10 @@ static void __msgs_readfile(char *name, msgs_block *mb)
size = _swi(MessageTrans_FileInfo, _IN(1)|_RETURN(2), name);
data = malloc(size);
if (!data) {
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _IN(0)|_IN(1)|_IN(2), "\0\0\0\0NoMem", 0, 0), 0);
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _INR(0,2), "\0\0\0\0NoMem", 0, 0), 0);
exit(1);
}
err = _swix(MessageTrans_OpenFile, _IN(0)|_IN(1)|_IN(2), &mb->cb, name, data);
err = _swix(MessageTrans_OpenFile, _INR(0,2), &mb->cb, name, data);
if (err) {
wimpt_reporterror(err, 0);
exit(1);
......@@ -90,7 +99,8 @@ static void __msgs_readfile(char *name, msgs_block *mb)
} while (p < e);
lines = malloc(n * 4);
if (!lines) {
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _IN(0)|_IN(1)|_IN(2), "\0\0\0\0NoMem", 0, 0), 0);
_swix(MessageTrans_CloseFile, _IN(0), &mb->cb);
wimpt_reporterror((os_error *)_swix(MessageTrans_ErrorLookup, _INR(0,2), "\0\0\0\0NoMem", 0, 0), 0);
exit(1);
}
p = data + 4;
......@@ -188,4 +198,5 @@ void msgs_init(void)
res_findname("Messages", name);
__msgs_readfile(name, &main_msgs_block);
atexit(__msgs_closefiles);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment