lib_a-mbstowcs.$(OBJEXT) lib_a-mbstowcs_r.$(OBJEXT) \
lib_a-mbtowc.$(OBJEXT) lib_a-mbtowc_r.$(OBJEXT) \
lib_a-mlock.$(OBJEXT) lib_a-mprec.$(OBJEXT) \
- lib_a-mstats.$(OBJEXT) lib_a-rand.$(OBJEXT) \
- lib_a-rand_r.$(OBJEXT) lib_a-realloc.$(OBJEXT) \
- lib_a-reallocf.$(OBJEXT) lib_a-sb_charsets.$(OBJEXT) \
- lib_a-strtod.$(OBJEXT) lib_a-strtol.$(OBJEXT) \
- lib_a-strtoul.$(OBJEXT) lib_a-utoa.$(OBJEXT) \
- lib_a-wcstod.$(OBJEXT) lib_a-wcstol.$(OBJEXT) \
- lib_a-wcstoul.$(OBJEXT) lib_a-wcstombs.$(OBJEXT) \
- lib_a-wcstombs_r.$(OBJEXT) lib_a-wctomb.$(OBJEXT) \
- lib_a-wctomb_r.$(OBJEXT) $(am__objects_1)
+ lib_a-mstats.$(OBJEXT) lib_a-quick_exit.$(OBJEXT) \
+ lib_a-rand.$(OBJEXT) lib_a-rand_r.$(OBJEXT) \
+ lib_a-realloc.$(OBJEXT) lib_a-reallocf.$(OBJEXT) \
+ lib_a-sb_charsets.$(OBJEXT) lib_a-strtod.$(OBJEXT) \
+ lib_a-strtol.$(OBJEXT) lib_a-strtoul.$(OBJEXT) \
+ lib_a-utoa.$(OBJEXT) lib_a-wcstod.$(OBJEXT) \
+ lib_a-wcstol.$(OBJEXT) lib_a-wcstoul.$(OBJEXT) \
+ lib_a-wcstombs.$(OBJEXT) lib_a-wcstombs_r.$(OBJEXT) \
+ lib_a-wctomb.$(OBJEXT) lib_a-wctomb_r.$(OBJEXT) \
+ $(am__objects_1)
am__objects_3 = lib_a-cxa_atexit.$(OBJEXT) \
lib_a-cxa_finalize.$(OBJEXT) lib_a-drand48.$(OBJEXT) \
lib_a-ecvtbuf.$(OBJEXT) lib_a-efgcvt.$(OBJEXT) \
gdtoa-gethex.lo gdtoa-hexnan.lo getenv.lo getenv_r.lo itoa.lo \
labs.lo ldiv.lo ldtoa.lo malloc.lo mblen.lo mblen_r.lo \
mbstowcs.lo mbstowcs_r.lo mbtowc.lo mbtowc_r.lo mlock.lo \
- mprec.lo mstats.lo rand.lo rand_r.lo realloc.lo reallocf.lo \
- sb_charsets.lo strtod.lo strtol.lo strtoul.lo utoa.lo \
- wcstod.lo wcstol.lo wcstoul.lo wcstombs.lo wcstombs_r.lo \
- wctomb.lo wctomb_r.lo $(am__objects_8)
+ mprec.lo mstats.lo quick_exit.lo rand.lo rand_r.lo realloc.lo \
+ reallocf.lo sb_charsets.lo strtod.lo strtol.lo strtoul.lo \
+ utoa.lo wcstod.lo wcstol.lo wcstoul.lo wcstombs.lo \
+ wcstombs_r.lo wctomb.lo wctomb_r.lo $(am__objects_8)
am__objects_10 = cxa_atexit.lo cxa_finalize.lo drand48.lo ecvtbuf.lo \
efgcvt.lo erand48.lo jrand48.lo lcong48.lo lrand48.lo \
mrand48.lo msize.lo mtrim.lo nrand48.lo rand48.lo seed48.lo \
environ.c envlock.c eprintf.c exit.c gdtoa-gethex.c \
gdtoa-hexnan.c getenv.c getenv_r.c itoa.c labs.c ldiv.c \
ldtoa.c malloc.c mblen.c mblen_r.c mbstowcs.c mbstowcs_r.c \
- mbtowc.c mbtowc_r.c mlock.c mprec.c mstats.c rand.c rand_r.c \
- realloc.c reallocf.c sb_charsets.c strtod.c strtol.c strtoul.c \
- utoa.c wcstod.c wcstol.c wcstoul.c wcstombs.c wcstombs_r.c \
- wctomb.c wctomb_r.c $(am__append_1)
+ mbtowc.c mbtowc_r.c mlock.c mprec.c mstats.c quick_exit.c \
+ rand.c rand_r.c realloc.c reallocf.c sb_charsets.c strtod.c \
+ strtol.c strtoul.c utoa.c wcstod.c wcstol.c wcstoul.c \
+ wcstombs.c wcstombs_r.c wctomb.c wctomb_r.c $(am__append_1)
@NEWLIB_NANO_MALLOC_FALSE@MALIGNR = malignr
@NEWLIB_NANO_MALLOC_TRUE@MALIGNR = nano-malignr
@NEWLIB_NANO_MALLOC_FALSE@MALLOPTR = malloptr
lib_a-mstats.obj: mstats.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-mstats.obj `if test -f 'mstats.c'; then $(CYGPATH_W) 'mstats.c'; else $(CYGPATH_W) '$(srcdir)/mstats.c'; fi`
+lib_a-quick_exit.o: quick_exit.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-quick_exit.o `test -f 'quick_exit.c' || echo '$(srcdir)/'`quick_exit.c
+
+lib_a-quick_exit.obj: quick_exit.c
+ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-quick_exit.obj `if test -f 'quick_exit.c'; then $(CYGPATH_W) 'quick_exit.c'; else $(CYGPATH_W) '$(srcdir)/quick_exit.c'; fi`
+
lib_a-rand.o: rand.c
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-rand.o `test -f 'rand.c' || echo '$(srcdir)/'`rand.c
--- /dev/null
+/*-
+ * Copyright (c) 2011 David Chisnall
+ * Copyright (c) 2015 embedded brains GmbH
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#include <stdlib.h>
+#include <sys/lock.h>
+
+/**
+ * Linked list of quick exit handlers. This is simpler than the atexit()
+ * version, because it is not required to support C++ destructors or
+ * DSO-specific cleanups.
+ */
+struct quick_exit_handler {
+ struct quick_exit_handler *next;
+ void (*cleanup)(void);
+};
+
+/**
+ * Lock protecting the handlers list.
+ */
+__LOCK_INIT(static, atexit_mutex);
+/**
+ * Stack of cleanup handlers. These will be invoked in reverse order when
+ */
+static struct quick_exit_handler *handlers;
+
+int
+at_quick_exit(void (*func)(void))
+{
+ struct quick_exit_handler *h;
+
+ h = malloc(sizeof(*h));
+
+ if (NULL == h)
+ return (1);
+ h->cleanup = func;
+ __lock_acquire(atexit_mutex);
+ h->next = handlers;
+ handlers = h;
+ __lock_release(atexit_mutex);
+ return (0);
+}
+
+void
+quick_exit(int status)
+{
+ struct quick_exit_handler *h;
+
+ /*
+ * XXX: The C++ spec requires us to call std::terminate if there is an
+ * exception here.
+ */
+ for (h = handlers; NULL != h; h = h->next)
+ h->cleanup();
+ _exit(status);
+}