Skip to content

Commit e637abc

Browse files
committed
use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by polluks)
1 parent ccd4f8c commit e637abc

File tree

11 files changed

+32
-31
lines changed

11 files changed

+32
-31
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Improvements:
66
Bug Fixes:
77

88
* examples: tetris code cleanup, use custom fonts
9+
* use EXIT\_FAILURE for fatal error conditions (fixes issue #13 by polluks)
910

1011
## 0.8.1
1112

src/compiler/aqb.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static void check_amigaos_env(void)
102102
if ( ((struct Library *)DOSBase)->lib_Version < 37)
103103
{
104104
U_request (NULL, NULL, "OK", "DOS library V%d is too old, need at least V37", ((struct Library *)DOSBase)->lib_Version);
105-
exit(1);
105+
exit(EXIT_FAILURE);
106106
}
107107

108108
struct Process *aqbProc;

src/compiler/compiler.c

+18-18
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
101101
if (!sourcef)
102102
{
103103
LOG_printf (LOG_ERROR, "failed to read %s: %s\n\n", sourcefn, strerror(errno));
104-
CO_exit(2);
104+
CO_exit(EXIT_FAILURE);
105105
}
106106

107107
frags = FE_sourceProgram(sourcef, sourcefn, /*is_main=*/!symfn, module_name);
@@ -110,7 +110,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
110110
if (EM_anyErrors)
111111
{
112112
LOG_printf (LOG_ERROR, "\n\nfrontend processing failed - exiting.\n");
113-
CO_exit(3);
113+
CO_exit(EXIT_FAILURE);
114114
}
115115

116116
LOG_printf (OPT_get(OPTION_VERBOSE) ? LOG_INFO : LOG_DEBUG, "\n\nsemantics worked.\n");
@@ -129,7 +129,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
129129
else
130130
{
131131
LOG_printf (LOG_ERROR, "\n** ERROR: failed to write symbol file %s .\n", symfn);
132-
CO_exit(4);
132+
CO_exit(EXIT_FAILURE);
133133
}
134134
}
135135

@@ -164,7 +164,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
164164
if (!RA_regAlloc(frame, body) || EM_anyErrors)
165165
{
166166
LOG_printf (LOG_ERROR, "\n\nregister allocation failed - exiting.\n");
167-
CO_exit(5);
167+
CO_exit(EXIT_FAILURE);
168168
}
169169

170170
CG_procEntryExitAS(frag);
@@ -185,7 +185,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
185185
if (!out)
186186
{
187187
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_gas_fn);
188-
CO_exit(6);
188+
CO_exit(EXIT_FAILURE);
189189
}
190190
CG_writeASMFile (out, frags, AS_dialect_gas);
191191
fclose(out);
@@ -197,7 +197,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
197197
if (!out)
198198
{
199199
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_asmpro_fn);
200-
CO_exit(7);
200+
CO_exit(EXIT_FAILURE);
201201
}
202202
CG_writeASMFile (out, frags, AS_dialect_ASMPro);
203203
fclose(out);
@@ -209,7 +209,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
209209
if (!out)
210210
{
211211
LOG_printf (LOG_ERROR, "\n\nfailed to open asm file %s for writing.\n", asm_vasm_fn);
212-
CO_exit(8);
212+
CO_exit(EXIT_FAILURE);
213213
}
214214
CG_writeASMFile (out, frags, AS_dialect_vasm);
215215
fclose(out);
@@ -245,21 +245,21 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
245245
U_memstat();
246246

247247
if (!AS_assembleCode (obj, body, expt, frame))
248-
CO_exit(9);
248+
CO_exit(EXIT_FAILURE);
249249

250250
break;
251251
}
252252
case CG_stringFrag:
253253
AS_assembleDataAlign2 (obj);
254254
if (!AS_assembleString (obj, frag->u.stringg.label, frag->u.stringg.str, frag->u.stringg.msize))
255-
CO_exit(10);
255+
CO_exit(EXIT_FAILURE);
256256
break;
257257
case CG_dataFrag:
258258
if (!frag->u.data.size)
259259
break;
260260
AS_assembleDataAlign2 (obj);
261261
if (!AS_assembleDataLabel (obj, frag->u.data.label, frag->u.data.expt, frag->u.data.ty))
262-
CO_exit(11);
262+
CO_exit(EXIT_FAILURE);
263263
if (frag->u.data.init)
264264
{
265265
for (CG_dataFragNode n=frag->u.data.init; n; n=n->next)
@@ -268,7 +268,7 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
268268
{
269269
case CG_labelNode:
270270
if (!AS_assembleDataLabel (obj, n->u.label, /*expt=*/FALSE, /*ty=*/NULL))
271-
CO_exit(12);
271+
CO_exit(EXIT_FAILURE);
272272
break;
273273
case CG_constNode:
274274
{
@@ -331,14 +331,14 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
331331
if (EM_anyErrors)
332332
{
333333
LOG_printf (LOG_ERROR, "\n\nassembler failed - exiting.\n");
334-
CO_exit(13);
334+
CO_exit(EXIT_FAILURE);
335335
}
336336

337337
if (objfn)
338338
LI_segmentWriteObjectFile (obj, objfn);
339339

340340
if (!binfn)
341-
CO_exit(0);
341+
CO_exit(EXIT_FAILURE);
342342

343343
/*
344344
* machine code generation (link phase)
@@ -352,12 +352,12 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
352352
if (!fObj)
353353
{
354354
LOG_printf (LOG_ERROR, "*** ERROR: failed to open startup.o\n\n");
355-
CO_exit(14);
355+
CO_exit(EXIT_FAILURE);
356356
}
357357
if (!LI_segmentListReadObjectFile (UP_link, sl, "startup.o", fObj))
358358
{
359359
fclose(fObj);
360-
CO_exit(15);
360+
CO_exit(EXIT_FAILURE);
361361
}
362362
fclose(fObj);
363363

@@ -375,20 +375,20 @@ int CO_compile(string sourcefn, string module_name, string symfn, string objfn,
375375
if (!fObj)
376376
{
377377
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s\n\n", mod_fn);
378-
CO_exit(16);
378+
CO_exit(EXIT_FAILURE);
379379
}
380380
if (!LI_segmentListReadObjectFile (UP_link, sl, S_name(n->m->name), fObj))
381381
{
382382
fclose(fObj);
383-
CO_exit(17);
383+
CO_exit(EXIT_FAILURE);
384384
}
385385
fclose(fObj);
386386
}
387387

388388
if (!LI_link (UP_link, sl))
389389
{
390390
LOG_printf (LOG_ERROR, "*** ERROR: failed to link.\n\n");
391-
CO_exit(18);
391+
CO_exit(EXIT_FAILURE);
392392
}
393393

394394
LI_segmentListWriteLoadFile (sl, binfn);

src/compiler/dis68k.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ void DEBUG_disasm(IDE_instance ed, unsigned long int start, unsigned long int en
10331033
} break;
10341034

10351035
default : printf("opnum out of range in switch (=%i)\n", opnum);
1036-
exit(1);
1036+
exit(EXIT_FAILURE);
10371037
}
10381038
}
10391039
if (decoded) opnum = 88;

src/compiler/env.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static void env_fail (string msg)
303303
modf = NULL;
304304
}
305305

306-
exit(126);
306+
exit(EXIT_FAILURE);
307307
}
308308

309309
static void fwrite_double(FILE *f, double d)

src/compiler/ide.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ static bool _ide_save (IDE_instance ed, bool save_as)
14761476
if (!sourcef)
14771477
{
14781478
fprintf(stderr, "failed to write %s: %s\n\n", ed->sourcefn, strerror(errno));
1479-
exit(2);
1479+
exit(EXIT_FAILURE);
14801480
}
14811481

14821482
static char *indent_str = " ";

src/compiler/link.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void link_fail (string msg)
6262
g_fObjFile = NULL;
6363
}
6464

65-
CO_exit(127);
65+
CO_exit(EXIT_FAILURE);
6666
}
6767

6868
#if LOG_LEVEL == LOG_DEBUG
@@ -1265,7 +1265,7 @@ void LI_segmentWriteObjectFile (AS_object obj, string objfn)
12651265
if (!g_fObjFile)
12661266
{
12671267
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", objfn);
1268-
exit(128);
1268+
CO_exit(EXIT_FAILURE);
12691269
}
12701270
write_hunk_unit (objfn, g_fObjFile);
12711271

@@ -1299,7 +1299,7 @@ void LI_segmentListWriteLoadFile (LI_segmentList sl, string loadfn)
12991299
if (!g_fLoadFile)
13001300
{
13011301
LOG_printf (LOG_ERROR, "*** ERROR: failed to open %s for writing.\n\n", loadfn);
1302-
exit(128);
1302+
CO_exit(EXIT_FAILURE);
13031303
}
13041304
write_hunk_header (sl, g_fLoadFile);
13051305

src/compiler/options.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void OPT_init(void)
105105
if (snprintf (g_pref_fn, PATH_MAX, "%s/prefs.ini", aqb_home)<0)
106106
{
107107
fprintf (stderr, "prefs.ini path too long\n");
108-
exit(42);
108+
exit(EXIT_FAILURE);
109109
}
110110
#endif
111111

src/compiler/ui_linux.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ static uint16_t UI_getch (void)
286286
char c, seq[5];
287287
while ((nread = read(STDIN_FILENO,&c,1)) == 0);
288288
if (nread == -1)
289-
exit(1);
289+
exit(EXIT_FAILURE);
290290

291291
while(1)
292292
{

src/compiler/util.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ static void *checked_malloc (size_t len)
9696
if (!p)
9797
{
9898
LOG_printf(LOG_ERROR, "\nran out of memory!\n");
99-
exit(1);
99+
exit(EXIT_FAILURE);
100100
}
101101
// fprintf(stderr, "checked_malloc len=%zu -> p=%p\n", len, p);
102102
return p;

src/tools/reactiontest/ratest.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,15 @@ int main(void)
105105
cleanexit("failed to open intuition.library\n");
106106
DPRINTF ("intuition.library opened\n");
107107

108-
if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 47)) )
108+
if (! (WindowBase = OpenLibrary((STRPTR)"window.class", 37)) )
109109
cleanexit("failed to open window.class\n");
110110
DPRINTF ("window.class opened\n");
111111

112-
if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 47)) )
112+
if (! (LayoutBase = OpenLibrary((STRPTR)"gadgets/layout.gadget", 37)) )
113113
cleanexit("failed to open gadgets/layout.gadget\n");
114114
DPRINTF ("gadgets/layout.gadget opened\n");
115115

116-
if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 47)) )
116+
if (! (ButtonBase = OpenLibrary((STRPTR)"gadgets/button.gadget", 0)) )
117117
cleanexit("failed to open gadgets/button.gadget\n");
118118
DPRINTF ("gadgets/button.gadget opened\n");
119119

0 commit comments

Comments
 (0)