|
| 1 | +/* Copyright 2016 Samsung Electronics Co., Ltd. |
| 2 | + * Copyright 2016 University of Szeged |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +#include <stdlib.h> |
| 18 | + |
| 19 | +#include "jerry-port.h" |
| 20 | +#include "jerry-port-default.h" |
| 21 | + |
| 22 | +static bool abort_on_fail = false; |
| 23 | + |
| 24 | +/** |
| 25 | + * Sets whether 'abort' should be called instead of 'exit' upon exiting with |
| 26 | + * non-zero exit code in the default implementation of jerry_port_fatal. |
| 27 | + */ |
| 28 | +void jerry_port_default_set_abort_on_fail (bool flag) /**< new value of 'abort on fail' flag */ |
| 29 | +{ |
| 30 | + abort_on_fail = flag; |
| 31 | +} /* jerry_port_default_set_abort_on_fail */ |
| 32 | + |
| 33 | +/** |
| 34 | + * Check whether 'abort' should be called instead of 'exit' upon exiting with |
| 35 | + * non-zero exit code in the default implementation of jerry_port_fatal. |
| 36 | + * |
| 37 | + * @return true - if 'abort on fail' flag is set, |
| 38 | + * false - otherwise. |
| 39 | + */ |
| 40 | +bool jerry_port_default_is_abort_on_fail () |
| 41 | +{ |
| 42 | + return abort_on_fail; |
| 43 | +} /* jerry_port_default_is_abort_on_fail */ |
| 44 | + |
| 45 | +/** |
| 46 | + * Default implementation of jerry_port_fatal. |
| 47 | + */ |
| 48 | +void jerry_port_fatal (jerry_fatal_code_t code) |
| 49 | +{ |
| 50 | + if (code != 0 |
| 51 | + && code != ERR_OUT_OF_MEMORY |
| 52 | + && jerry_port_default_is_abort_on_fail ()) |
| 53 | + { |
| 54 | + abort (); |
| 55 | + } |
| 56 | + else |
| 57 | + { |
| 58 | + exit (code); |
| 59 | + } |
| 60 | +} /* jerry_port_fatal */ |
0 commit comments