Partial buffer slicing.
[SquirrelJME.git] / nanocoat / lib / base / error.c
blob45d0cb1832d3b02195f55325ca886cab15647ef5
1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include <stdarg.h>
12 #include "sjme/error.h"
14 sjme_errorCode sjme_error_also(
15 sjme_errorCode error, sjme_errorCode expression)
17 /* Keep existing error. */
18 if (sjme_error_is(error))
19 return error;
21 /* Return the error from the expression. */
22 return expression;
25 sjme_errorCode sjme_error_alsoV(
26 sjme_errorCode error, ...)
28 va_list va;
29 sjme_errorCode result, now;
31 /* Start reading. */
32 va_start(va, error);
34 /* Read in until the end of sequence. */
35 result = error;
36 for (;;)
38 /* Read in next. */
39 now = va_arg(va, sjme_errorCode);
41 /* End? */
42 if (now == SJME_NUM_ERROR_CODES)
43 break;
45 /* Perform the normal also call. */
46 result = sjme_error_also(result, result);
49 /* End. */
50 va_end(va);
52 /* Return the given result. */
53 return result;
56 sjme_errorCode sjme_error_alsoVEnd(void)
58 /* The number of error codes is considered the end. */
59 return SJME_NUM_ERROR_CODES;
62 sjme_jboolean sjme_error_is(
63 sjme_errorCode error)
65 return error < SJME_ERROR_NONE;
68 sjme_errorCode sjme_error_default(
69 sjme_errorCode error)
71 return sjme_error_defaultOr((error), SJME_ERROR_UNKNOWN);
74 sjme_errorCode sjme_error_defaultOr(
75 sjme_errorCode error, sjme_errorCode otherwise)
77 if (!sjme_error_is(error) || error == SJME_ERROR_UNKNOWN)
79 if (!sjme_error_is(otherwise))
80 return SJME_ERROR_UNKNOWN;
81 else
82 return otherwise;
85 return error;